0
String s =  "something";
Class<?> c1 = s.getclass();
Class<?> c2 = Class.forname("java.lang.String");
Class<?> c3 = java.lang.String.class;

What is different between c1, c2, c3?

If I load a class with different class-loader, there will be different class of that class in runtime.

Classloader cl1 = new URLClassloader(...) ;
Classloader cl2 = new URLClassloader(...) ;

Class<?> x1 = Class.forname("java.lang.String", cl1);
Class<?> x2 = Class.forname("java.lang.String", cl2);

x1 and x2 are not the same why?

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197

1 Answers1

0

A bit of search would give you the answer:

https://stackoverflow.com/a/19559463/13745944

As said by Matthias: "if a class is loaded by two different class loaders, this class exists twice within the VM" therefore x1 is different from x2 because you're using different class loaders.

There's no difference between the c1, c2, c3 cause they use the same class loader.

Mak
  • 11
  • 2