Looks like another casualty of type erasure, but I'm not in a position to check it out right now.
–
Michael Myers♦Nov 27 '09 at 18:33

I'd like an explanation for what you're really trying to do here, because on the face of it this design makes no sense to me. I understand Loadable and LoadableFactory, but what's the reference class doing for you, and why does it have to have a factory as a private data member?
–
duffymoNov 27 '09 at 18:57

Thanks everybody for your answers all of them were useful to me! As for what I'm trying to do, I won't get into details, but the sample you're seeing lacks all the nasty details I really have in my code and I don't want to hurt your brains to try and understand all the reasons behind that :). Just wanted to understand what to make of this. So now as I understand - Java is wrong but java is compiling so I'll need to deal with it ;).
–
inkrediblNov 28 '09 at 9:16

I don't see how it is applicable - presumably this is a compiler error, and at compile-time all type information available. JavaDoc for Object.getClass even have this bit: "The actual result type is Class<? extends |X|> where |X| is the erasure of the static type of the expression on which getClass is called. For example, no cast is required in this code fragment: Number n = 0; Class<? extends Number> c = n.getClass();"
–
Pavel MinaevNov 27 '09 at 23:50

This stuff hurts my head to think about, so I won't try to explain it. Suffice it to say that there are some operations you'd expect to work, but because Java "forgets" the generic details of types between modules, they don't.

You're probably not in a position to use this information, but the same person who built generics into Java has gone and designed a whole new Java-like language: It's called Scala. Scala handles types and generics a whole lot more competently; you could say it does everything right in this respect. It also runs in the JVM and you can call between Scala and Java classes.

My personal take on Scala, though, is that it's a system for artfully managing complex types that incidentally can also be used as a programming language. :)