Class type required but T found

前端 未结 3 2005
误落风尘
误落风尘 2020-12-10 15:16

I can\'t create an actor for some reason (here is a simple version of my class hierarchy):

abstract class Class1[T <: Class2[_]: ClassTag] extends Actor {         


        
3条回答
  •  佛祖请我去吃肉
    2020-12-10 15:33

    I think this is because of JVM restriction also known as "type erasure". http://docs.oracle.com/javase/tutorial/java/generics/erasure.html

    also see "Cannot Create Instances of Type Parameters" at http://docs.oracle.com/javase/tutorial/java/generics/restrictions.html

    By the way C# allows you to write:

    new T()
    

    when you define a restriction

    where T: new()
    

    but unfortunately constructor must be parameterless

提交回复
热议问题