Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Import non-packaged class

Reply
Thread Tools

Import non-packaged class

 
 
nivanson@gmail.com
Guest
Posts: n/a
 
      10-01-2006
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!

 
Reply With Quote
 
 
 
 
=?ISO-8859-1?Q?Arne_Vajh=F8j?=
Guest
Posts: n/a
 
      10-01-2006
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> 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
 
Reply With Quote
 
 
 
 
nivanson
Guest
Posts: n/a
 
      10-01-2006
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

Arne Vajh°j wrote:
> (E-Mail Removed) wrote:
> > 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


 
Reply With Quote
 
=?ISO-8859-1?Q?Arne_Vajh=F8j?=
Guest
Posts: n/a
 
      10-01-2006
nivanson wrote:
> 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.
 
Reply With Quote
 
nivanson
Guest
Posts: n/a
 
      10-01-2006

Arne Vajh°j wrote:
> nivanson wrote:
> > 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.


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 ^^

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
to use import java.lang.* or import java.lang.Math or none at all? JPractitioner Java 13 02-24-2006 08:48 PM
Class A contains class B, class B points to class A Joseph Turian C++ 5 12-30-2005 03:24 PM
Nested Class, Member Class, Inner Class, Local Class, Anonymous Class E11 Java 1 10-12-2005 03:34 PM
A parameterized class (i.e. template class / class template) is not a class? christopher diggins C++ 16 05-04-2005 12:26 AM
IMPORT STATIC; Why is "import static" file scope? Why not class scope? Paul Opal Java 12 10-10-2004 11:01 PM



Advertisments