This is self answered question meant to share some knowledge from http://java.dzone.com/articles/understanding-sunmiscunsafe
I am using Oracle HotSpot Java Virtual Machine.
Suppose I have a class A
and I want to create an instance of this class without calling its constructor (lets say that constructor is private, expensive, or simply does things I want to avoid).
For instance how to create instance of this class
class A{
private A(){
System.exit(0);//or any task I want to avoid
}
}
without making my application exit? Is it possible?