Java, ++.
, , hasAtleastOne().
class Example {
private static int noOfInstances = 0;
public Example() {
noOfInstances++;
}
public static boolean hasAtleastOne() {
if(noOfInstances > 0)
return true;
else
return false;
}
protected void finalize() throws Throwable {
noOfInstances--;
}
}
, Java, ++. , , - , . , , .
, , , finalize() , , . - , - ; , , .
You could add extra reliability to the solution by implementing the Dispose pattern . It also requires the class client to call the dispose method to signal that the instance should be deleted, so that the instance counter can be reduced. Poorly written clients will make the decision unreliable.
source
share