>> It is trivial
>> to see that the list of all possible Foo package classes is finite and
[quoted text clipped - 7 lines]
> as
> bytes using Sun's peculiar not-really-UTF-8 character encoding.
Hmm... I had considered that two classes are "the same" not merely if
they had the same name, but if they had the same bytecode.
That is, I had made a class "foo.Bar" and threw it into a black hole,
and someone else wrote a "foo.Bar" class and kept it around, I would not say
that these are the same classes, unless they had the same implementation.
So let's say further that I didn't actually write my foo.Bar class, but
rather, I wrote a program to generate the foo.Bar class for me. The program
uses a random number generator to generate a random (but legal!) sequence of
bytecodes, saves that to the disk, and throw the whole computer into the
black hole. Obviously, there was a USB dongle that somehow generates "true"
random numbers (perhaps via measuring of radioactive decay of some
substance), and just for the heck of it, that was thrown into the black hole
as well. So even if you tortured me, or injected me with truth serum, I
could not tell you the sequence of bytecodes that made up my foo.Bar class.
> So there's definitely a limit to how many different classes can be in the
> same
[quoted text clipped - 8 lines]
> the
> order of 1e650000.
I know there's a limit on the length of the methods, and on the number
of methods itself, so that would imply there's a limit to the list of all
possible classes (not merely all possible class names). But if we accept
that maybe the question was loosely phrased, we might allow say that if
foo.Bar contains a nested inner class foo.Bar.Buntz, then that is "part of"
the foo.Bar class as well. If we do allow this, then unless there's a limit
to the levels of nesting and the number of allowed nested classes, then we
have an infinte number of possibilities.
> (Obviously the list of all possible /classes/ is a bit longer, but they
> can't
> all be members of the same package/classloader combination at the same
> time.)
Right, this makes it *difficult* to get all possible classes within a
package, but not nescessarily impossible: You'd just have to use more than 1
classloader per package.
> Since these are moderately large numbers, the OP's desired:
> Package.getClasses("java.lang.*");
> method would have to return an Iterator<Class<?>> rather than an actual
> array
> or List of class objects, but that's only a minor technical hurdle.
In this sense, actually, you could conceptually be returning an
"infinite" number of classes. The iterator just never returns "false" for
hasNext(). So maybe this whole project is possible after all. The next()
method of the iterator would just need to return every possible bytecode
sequence that yields a valid class file, probably in lexigraphical order of
the bytecode sequence. The only tricky part is coordinating this so that if
classes have the same name, they claim to have been loaded by different
class loaders.
- Oliver
Furious George - 25 May 2006 16:12 GMT
> >> It is trivial
> >> to see that the list of all possible Foo package classes is finite and
[quoted text clipped - 46 lines]
> to the levels of nesting and the number of allowed nested classes, then we
> have an infinte number of possibilities.
The classfile format imposes a hard limit of 2**16 on the length of the
fully qualified class file name. Unless I am mistaken, that does
impose a limit on both the levels of nesting and the number of allowed
nested classes. Thus there exists only a finite number of
possibilities. But as you later point out, it does not really matter
if the list is finite or infinite.
> > (Obviously the list of all possible /classes/ is a bit longer, but they
> > can't
[quoted text clipped - 19 lines]
> classes have the same name, they claim to have been loaded by different
> class loaders.
This is easy. Every class gets its own classloader.
> - Oliver
Oliver Wong - 25 May 2006 16:42 GMT
>> The only tricky part is coordinating this so that if
>> classes have the same name, they claim to have been loaded by different
>> class loaders.
>
> This is easy. Every class gets its own classloader.
Pure genius! So I guess everyone who told the OP that this was
impossible (which includes myself) were in fact wrong.
- Oliver
Furious George - 25 May 2006 17:15 GMT
> >> The only tricky part is coordinating this so that if
> >> classes have the same name, they claim to have been loaded by different
[quoted text clipped - 4 lines]
> Pure genius! So I guess everyone who told the OP that this was
> impossible (which includes myself) were in fact wrong.
Actually pure idiocy, but you are right everyone who told the OP this
was impossible was wrong.
> - Oliver