+ 8
what is that
10 Antworten
+ 1
this feature is 'Class Literals' and the concept is 'reflection', there is a package java.lang.reflect, but some methods are declared in Object.
You can use it if you are exploring class or checking an unknown object,
e.g. if you get it as a parameter in a method or at debug time,
or if you are writing a program that displays the properties of objects eg IDE or with JSON
import java.lang.reflect.Method;
public class Program {
public static void main(String args[]) {
printMethods( String.class );
}
static void printMethods(Class<?> c){
for (Method m: c.getMethods() )
System.out.println(m.getName() +"()");
}
}
+ 5
I I understood but
B.class returns a Class object instead of B object?
+ 5
thanks I got it where to use this and what is it called as a concept or feature
+ 5
thanks I got it
+ 3
😂😂😂😂😂😂 it is not my code it is a challenge code , I like your code but don't advertise it
+ 1
class with name 'Class' (java.lang.Class<T>) is special class for to get an informations about classes in your code.
this program detects
. if class 'Simple' is interface (false)
. if class 'My' is interface (true)
then assigns Class type object which represent B class to c2
+ 1
yes, it returns Class<B> type object try c2 = new B();
B is class, there is no new B() for create object of type B,
but internally there is created object which stores informations about class B and you can get reference to it by B.class construct