Sorry for my "silly-from-side" questions, but
https://play.crystal-lang.org/#/r/2neg
abstract class A(T)
def foo
puts T.to_s
end
end
class B < A(Int32)
end
a = [] of A
a << B.new
a.each { |e| p e.foo }
# => Error in line 10: can't use A(T) as generic type argument yet, use a more specific type
It's weird, because A is abstract. Any workarounds?
You are not defining generic type on line 10:
abstract class A(T)
def foo
puts T.to_s
end
end
class B < A(Int32)
end
a = [] of A(Int32) # <<<
a << B.new
a.each { |e| p e.foo }
@hugoabonizio the whole point of Generics is that there might be class C < A(String) or < A(AnotherType). There might be any amount of other classes.
@vladfaust But in [] of A, T is not specified. It could be anything. And that's not supported by the compiler... basically T would be Object here, but that's not supported...
@asterite will supporting Object be implemented some day?
Most helpful comment
https://www.youtube.com/watch?v=EkPy18xW1j8