Skip to content

Instantly share code, notes, and snippets.

@SansWord
Last active December 18, 2019 06:26
Show Gist options
  • Save SansWord/c527507d0f7f062da62a71faf0cb9077 to your computer and use it in GitHub Desktop.
Save SansWord/c527507d0f7f062da62a71faf0cb9077 to your computer and use it in GitHub Desktop.
package com;
import java.lang.invoke.MethodHandles;
public abstract class TestStatic {
private static Class classInstance = MethodHandles.lookup().lookupClass();
public Class getClassInstance() {
return classInstance;
}
public static void main(final String[] args) {
System.out.println(new A().getClassInstance().getCanonicalName());
System.out.println(new B().getClassInstance().getCanonicalName());
System.out.println(new C().getClassInstance().getCanonicalName());
}
}
class A extends TestStatic {
}
class B extends TestStatic {
}
class C extends A {
}
@SansWord
Copy link
Author

SansWord commented Jul 2, 2019

Wondering is there any way to change behavior to make A, B, C to have different name.
But I still want to make the variable static. Or at least one instance each class rather than each instance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment