silly java puzzle

R

Roedy Green

This is a puzzle for people with too much time.

How can you create an outer class that nobody but you can call, not
even members of your same package?

Hint enum was not always a reserved word.
 
D

Daniel Dyer

This is a puzzle for people with too much time.

How can you create an outer class that nobody but you can call, not
even members of your same package?

Hint enum was not always a reserved word.

Is this assuming that your other classes are written in Java 5? Your hint
suggests that you would create a class called 'enum' (or perhaps 'assert')
with Java 1.4 or earlier and then attempt to use it from Java 5.

Dan.
 
R

Raymond DeCampo

Roedy said:
This is a puzzle for people with too much time.

How can you create an outer class that nobody but you can call, not
even members of your same package?

Hint enum was not always a reserved word.

I'm not sure why you would want to do this (academic exercise?). What
exactly do you mean by "only you can call"? Specifically, who is "you"
(you the person; you the class; etc) and what do you mean by "call"
(calling a class doesn't compute, I assume you mean something else.

If you simply have a private class listed in a file, wouldn't that
suffice? I guess the class could be activated by Class.forName() or
some such thing.

Ray
 
R

Roedy Green

If you simply have a private class listed in a file, wouldn't that
suffice? I guess the class could be activated by Class.forName() or
some such thing.

I don't think there is such a thing as a private class unless you
built it with byte code.
 
C

Chris Uppal

Daniel said:
Is this assuming that your other classes are written in Java 5? Your hint
suggests that you would create a class called 'enum' (or perhaps 'assert')
with Java 1.4 or earlier and then attempt to use it from Java 5.

If we are allowed to play games:

$ java -version
java version "1.5.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-b64)
Java HotSpot(TM) Client VM (build 1.5.0-b64, mixed mode, sharing)

$ java -cp . this
Hello from this!

$ java -cp . class
Hello from class!

$ java -cp . null
Hello from null!

$ java -cp . 123
Hello from 123!

$ java -cp . ==
Hello from ==!

bytecode...

-- chris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top