Import non-packaged class

Discussion in 'Java' started by nivanson@gmail.com, Oct 1, 2006.

  1. Guest

    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!
     
    , Oct 1, 2006
    #1
    1. Advertising

  2. 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
     
    =?ISO-8859-1?Q?Arne_Vajh=F8j?=, Oct 1, 2006
    #2
    1. Advertising

  3. nivanson Guest

    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:
    > 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
     
    nivanson, Oct 1, 2006
    #3
  4. 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.
     
    =?ISO-8859-1?Q?Arne_Vajh=F8j?=, Oct 1, 2006
    #4
  5. nivanson Guest

    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 ^^
     
    nivanson, Oct 1, 2006
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jeff Gaynor
    Replies:
    2
    Views:
    355
    Jeff Gaynor
    Jul 14, 2004
  2. numlock
    Replies:
    8
    Views:
    440
    numlock
    Jul 29, 2004
  3. Replies:
    2
    Views:
    5,491
    Ross Bamford
    Apr 29, 2005
  4. Replies:
    3
    Views:
    430
    Scott Smith
    Dec 1, 2005
  5. Replies:
    3
    Views:
    589
    Mickey Segal
    Mar 29, 2006
Loading...

Share This Page