-2

Which is the java equivalent of c#

this.GetType().Namespace

to get the package name in which the class is contained?

UnDiUdin
  • 14,924
  • 39
  • 151
  • 249

1 Answers1

3

This is the package of a class:

Package myPackage = getClass().getPackage(); 

// or from a static context:
Package myPackage = MyClass.class.getPackage();

as a String:

String packageName = getClass().getPackage().getName();

// or from a static context:
String packageName = MyClass.class.getPackage().getName();
spi
  • 1,673
  • 13
  • 19
  • yes it works. I was fooled by the different namespave vs package names, i am transitioning to java and i am still somewhat confused on the basics – UnDiUdin Oct 11 '18 at 08:06