Home > Back-end >  Can we put the class as a parameter to preach to participate?
Can we put the class as a parameter to preach to participate?

Time:01-23

I want to write a method, pass in a method for class for class do some operation, excuse me if I can
Class Abc () {}

Public void AA (T T) {
Print (t.g etClass ());//here no, get the class is not Abc, but by the name of the class, how should do?
}

//call
AA (Abc)

CodePudding user response:

Of course, otherwise reflection can't use the
Public void AA (T T) {
Print (t.g etClass (). The getName ());//don't know what are you trying to get at, get the name of the class by getName
}

CodePudding user response:

 
Public class Test {
Public static void main (String [] args) {
Class GateWayClass=GateWay. The class;
The getClassName (gateWayClass);
}

Public static void getClassName (Class clazz) {
System. The out. Println (clazz. GetName ());
}
}

  • Related