Import non-packaged class

N

nivanson

Hi, I wonder if it's possible to package a .class file so that I can
import it from outside default package. It seems to me that you cannot
import classes in default package if you are not working in default
package.

So.
Is it possible to package a class that I don't have access to the
sourcecode to (it's not packaged at all...) so that I can access it
from outside default package and how do I do it?

Thanks!
 
?

=?ISO-8859-1?Q?Arne_Vajh=F8j?=

Hi, I wonder if it's possible to package a .class file so that I can
import it from outside default package. It seems to me that you cannot
import classes in default package if you are not working in default
package.

So.
Is it possible to package a class that I don't have access to the
sourcecode to (it's not packaged at all...) so that I can access it
from outside default package and how do I do it?

I don't think you can.

Which is a very good reason for always using packages !

As a workaround, then maybe you can use some reflection.

Arne
 
N

nivanson

Right...

We are using this file Prompt.class in class for console inputs with
validations of input types. I guess I'll stick with the Scanner for
now! We have no way of finding the sourcecode for this class since he
got it from some guy on a university. :S

Thanks
 
?

=?ISO-8859-1?Q?Arne_Vajh=F8j?=

nivanson said:
We are using this file Prompt.class in class for console inputs with
validations of input types. I guess I'll stick with the Scanner for
now! We have no way of finding the sourcecode for this class since he
got it from some guy on a university. :S

I would always prefer an official Java API class over
some code from the net.

Especially if the code from the net comes without
packages, because that does not imply good quality.

Arne

PS: If you have sufficient license rights to the code you
could decompile it, add package and recompile.
 
N

nivanson

Arne said:
I would always prefer an official Java API class over
some code from the net.

Especially if the code from the net comes without
packages, because that does not imply good quality.

Arne

PS: If you have sufficient license rights to the code you
could decompile it, add package and recompile.

It isn't good quality. -..- It even mixes swedish and english naming in
it's functions. Though it has some obvious advantages over the Scanner
that we also got introduced to. Sooner in our course we will write our
own input libraries I think... Or start using Swing or SWT (or qt4 if
my suggestion passes).

Thanks for answering my question! I'll try the decompiler for fun ^^
 

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

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top