As the title implies, or is it a pseudo-proposition?
thanks.
As the title implies, or is it a pseudo-proposition?
thanks.
I suppose you could have the static initializer for the class lock a global resource (like a file, socket):
public class MyClass{
static {
if (!lockFile())
throw new IllegalStateException("Attempt to load class twice");
}
...
}
of course, it is certainly possible to load a class more than once if you use multiple class loaders. Happens all the time in server apps.
As cletus says, proving a negative is hard to do. So you might want to refine your statement to something more narrow. You could say "according to the java language (or jvm) specification, a class is never loaded twice", and then cite the relevant portions of the spec. Or you could try "in sun's jvm, version XX.XX, a class is never loaded twice, as long as certain other conditions (like no funky classloaders) are met. (listing all conditions will be left as an exercise for the original poster).
For a naive proof, you could write a program with a class Foo that prints "hello world" in its static initializer, then instantiate 2 instances of Foo, and show everyone that only one "hello world" got printed out. That might suggest that a class doesn't get loaded every time an object of that class is created.
According to the Blackwell Dictionary of Western Philosophy, a "pseudo-proposition" is as follows:
A term introduced by Wittgenstein in the Tractatus, referring to any judgment that attempts to say that which can only be shown. Unlike other propositions, pseudo-propositions can not be analyzed into atomic pictures and their combinations and therefore they are not pictures of the world. Wittgenstein thinks that in different ways the propositions of logic, mathematics, the a priori parts of natural science, ethics, and philosophy – including the propositions of his own Tractatus – are all pseudo-propositions. Logical positivists develop this idea in their attack on metaphysics by saying that all propositions and statements that purport to make a factual claim but which can not be verified by experience are pseudo-propositions. They have emotional significance, but lack cognitive meaning. There are many attempts to retrieve at least some of the fields discarded in this way by logical positivism. “The propositions of mathematics are equations, and therefore pseudo-propositions.” Wittgenstein, Tractatus
If you are using "pseudo-proposition" in this sense, then your proposition is a pseudo-proposition even if we could develop a mathematical proof for it, since according to Wittgenstein all of mathematics is a pseudo-proposition. If is impossible to verify by observation that the proposition "class loading takes place only once" is always true.
But to me, this is only saying that the label "pseudo-proposition" is not a useful one when we are talking about IT topics. And that someone who uses it in this context either doesn't really understand the term, or is posturing.
I doubt that it is (even) possible to mathematically prove that a class is loaded only once, because you'd have to prove this for any (theoretically) possible class loader. But frankly, who cares! I'm happy to just declare that any class loader that allows a class to be loaded multiple times is broken.
(In fact, if you have multiple class loaders, it is possible to load the same bytecode file once in each class loader. But what you get from the perspective of the Java execution model is different classes with the same name.)