Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / July 2007

Tip: Looking for answers? Try searching our database.

Extending java.io.File

Thread view: 
ufan100@gmail.com - 06 Jul 2007 13:05 GMT
Hi, Is it possible to extend java.io.File?

javac (through Netbeans) gives me an error:

cannot find symbol:
symbol : constructor File()
location: class java.io.File
class Dir extends java.io.File {
1 error
BUILD FAILED (total time: 5 seconds)

Cheers
Lucas
Andrew Thompson - 06 Jul 2007 13:32 GMT
>Hi, Is it possible to extend java.io.File?

Sure.

>javac (through Netbeans)

Learn Java, not (friggin') netbeans.

>..gives me an error:

So stop using it, and (please) stop whining.

Signature

Andrew Thompson
http://www.athompson.info/andrew/

Eric Sosman - 06 Jul 2007 13:39 GMT
> Hi, Is it possible to extend java.io.File?

    I see no reason why not.

> javac (through Netbeans) gives me an error:
>
[quoted text clipped - 4 lines]
> 1 error
> BUILD FAILED (total time: 5 seconds)

    The problem isn't with File, but with your subclass.
You are attempting to call the no-argument constructor of
File, but File doesn't have such a constructor.

    You may not have written an explicit call on File's
constructor, either as `new File()' or as `super()' in a
FunnyFile constructor, but remember: a subclass' constructor
cannot start doing its job until its superclass' constructor
has finished.  The job of the FunnyFile constructor is to
take an existing File and specialize it; the File itself
is built by File's own constructor.  This "constructor
chaining" is so important that if you do not call `super()'
explicitly (perhaps with arguments), the compiler inserts a
no-argument `super()' call on your behalf.  And if the
superclass doesn't have a no-argument constructor, as File
doesn't, the no-argument `super()' call won't compile.

    Why doesn't the compiler call one of the constructors
File actually has, instead of calling one that doesn't
exist?  Well, which of them should it call, and with what
argument values?  The compiler cannot read your mind.

Signature

Eric Sosman
esosman@ieee-dot-org.invalid

ufan100@gmail.com - 06 Jul 2007 14:03 GMT
> ufan...@gmail.com wrote:
> > Hi, Is it possible to extend java.io.File?
[quoted text clipped - 35 lines]
> Eric Sosman
> esos...@ieee-dot-org.invalid

Thank you for taking the time ... I've clearly got some reading to do
Roedy Green - 07 Jul 2007 07:11 GMT
>cannot find symbol:
>symbol : constructor File()
>location: class java.io.File
>class Dir extends java.io.File {
>1 error
>BUILD FAILED (total time: 5 seconds)

your Dir constructors  must as the very first thing call super(...)
some constructor of File.

Also check that File is not final.
--
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.