Extending java.io.File

Discussion in 'Java' started by ufan100@gmail.com, Jul 6, 2007.

  1. Guest

    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
     
    , Jul 6, 2007
    #1
    1. Advertising

  2. Andrew Thompson, Jul 6, 2007
    #2
    1. Advertising

  3. Eric Sosman Guest

    wrote:
    > Hi, Is it possible to extend java.io.File?


    I see no reason why not.

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


    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.

    --
    Eric Sosman
    lid
     
    Eric Sosman, Jul 6, 2007
    #3
  4. Guest

    On Jul 6, 10:39 pm, Eric Sosman <> wrote:
    > wrote:
    > > Hi, Is it possible to extend java.io.File?

    >
    > I see no reason why not.
    >
    > > 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)

    >
    > 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.
    >
    > --
    > Eric Sosman
    >


    Thank you for taking the time ... I've clearly got some reading to do
     
    , Jul 6, 2007
    #4
  5. Roedy Green Guest

    On Fri, 06 Jul 2007 12:05:36 -0000, wrote, quoted or
    indirectly quoted someone who said :

    >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
     
    Roedy Green, Jul 7, 2007
    #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. Frank
    Replies:
    5
    Views:
    534
    Andrew Thompson
    Jan 14, 2005
  2. Hendrik Maryns

    Extending java.util.Set

    Hendrik Maryns, Feb 15, 2006, in forum: Java
    Replies:
    11
    Views:
    5,430
    Mike Schilling
    Feb 17, 2006
  3. Richard Maher
    Replies:
    10
    Views:
    608
    =?ISO-8859-1?Q?Arne_Vajh=F8j?=
    Feb 9, 2007
  4. Rakesh
    Replies:
    10
    Views:
    12,274
    Mike Schilling
    Apr 8, 2008
  5. Laura Schmidt
    Replies:
    8
    Views:
    136
    Roedy Green
    Jun 16, 2014
Loading...

Share This Page