Get class that extended this class's name.

Hey JGO, I’m trying to figure out how to get the class’s name that is extending my abstract StringPacket class.

I know how to get a class’s name:


String className = getClass().getName().replace(getClass().getPackage().getName()+".", "");

How would I inside my abstract class’s constructor obtain the class’s name that is extending the StringPacket class?

Here is my pseudo StringPacket class:


public class StringPacket {

	private String packetName;

	public StringPacket() {
		// How would I obtain the name of class extending this?
		packetName = ???;
	}
}

Thanks for any feedback/help JGO.


// require that subclasses provide name
public StringPacket(String name) {
      packetName = name;
}



// in subclass:
public SpecialPacket() {
      super("SpecialPacket"); // alternatively super(getClass().getSimpleName());
}


Thank you, I was able to obtain the class’s name extending this abstract class by calling:


getClass().getSimpleName()

Inside the constructor like I wanted to obtain it originally :slight_smile:

Thanks.