Click to enter _ more _java thousand ask
1, how to obtain the type class
In Java, you cannot get the type of the paradigm, for example:
publicclass Box<T> { publicstaticvoidmain(String[] args) { System.out.printf(T);//编译错误 }}
In fact, because Java is a strongly typed language, at compile time we do not know what the specific type of T is, only after the compilation, the different scenes are specified before they will know, so before compiling is unable to get the type of T. If you want to get the type of T, you can declare an object in the generic class and get the currently specified type through the object.
For example:
Public classtestgeneric<t> {PrivateT T; PublicTGett() {returnT } Public void Sett(T T) { This. T = t; } Public void Test() {System. out. println (T.getclass () +", "+ t); } Public Static void Main(string[] args) {Testgeneric<string> Testgeneric =NewTestgeneric<string> (); Testgeneric.sett ("Test"); Testgeneric.test (); }}
Java thousand asks _05 object-oriented (014) _ How to get the class classes of the paradigm