11th Sep 2019, 11:03 PM
ABADA S
ABADA S - avatar
7 Answers
+ 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() +"()"); } }
13th Sep 2019, 6:32 PM
zemiak
+ 5
I I understood but B.class returns a Class object instead of B object?
12th Sep 2019, 5:13 PM
ABADA S
ABADA S - avatar
+ 5
thanks I got it where to use this and what is it called as a concept or feature
12th Sep 2019, 11:30 PM
ABADA S
ABADA S - avatar
+ 5
thanks I got it
13th Sep 2019, 6:42 PM
ABADA S
ABADA S - avatar
+ 3
😂😂😂😂😂😂 it is not my code it is a challenge code , I like your code but don't advertise it
6th Oct 2019, 6:35 AM
ABADA S
ABADA S - avatar
+ 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
12th Sep 2019, 4:59 PM
zemiak
+ 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
12th Sep 2019, 7:05 PM
zemiak