What’s wrong with this reflection code? GetFields() is returning an empty array

The parameterless GetFields() returns public fields. If you want non-public ones, use: cc.GetType().GetFields(BindingFlags.Instance | BindingFlags.NonPublic); or whatever appropriate combination you want – but you do need to specify at least one of Instance and Static, otherwise it won’t find either. You can specify both, and indeed public fields as well, to get everything: cc.GetType().GetFields(BindingFlags.Instance | … Read more

What is the difference between bounded wildcard and type parameters?

They expose different interfaces and contract for the method. The first declaration should return a collection whose elements type is the same of the argument class. The compiler infers the type of N (if not specified). So the following two statements are valid when using the first declaration: Collection<Integer> c1 = getThatCollection(Integer.class); Collection<Double> c2 = … Read more

How to instantiate an instance of type represented by type parameter in Scala

EDIT – apologies, I only just noticed your first error. There is no way of instantiating a T at runtime because the type information is lost when your program is compiled (via type erasure) You will have to pass in some factory to achieve the construction: class BalanceActor[T <: Actor](val fac: () => T) extends … Read more