jeudi 21 janvier 2021

Find classes with same full qualified name in Java during runtime

Lets say I have a jar a.jar with a class com.company.ma.MyClass

package com.company.ma
public class MyClass {
  public void someMethod() {
    System.out.println("Hey");
  }
}

Also another jar b.jar with a class com.company.ma.MyClass but different implementation.

package com.company.ma
public class MyClass {
  public void anotherMethod() {
    System.out.println("This is different");
  }
}

The classes have the same full qualified name but they are different.

How can I find all classes in the classpath with a given full qualified name, say com.company.ma.MyClass and print it's location? In this example I'd expect two classes with name com.company.ma.MyClass in two different jars





Aucun commentaire:

Enregistrer un commentaire