Another simple problem

Discussion in 'Java' started by stud, Dec 9, 2004.

  1. stud

    stud Guest

    ERROR:
    invalid method declaration; return type required
    invalid method declaration; return type required

    what's wrong here?

    class insertFailException extends SQLException
    {
    public insertFailedException(String reason)
    {
    super (reason);
    }
    public insertFailedException()
    {
    super();
    }
    }
    stud, Dec 9, 2004
    #1
    1. Advertising

  2. On Thu, 9 Dec 2004 21:57:25 +0100, stud <> wrote:

    > ERROR:
    > invalid method declaration; return type required
    > invalid method declaration; return type required
    >
    > what's wrong here?
    >
    > class insertFailException extends SQLException
    > {
    > public insertFailedException(String reason)
    > {
    > super (reason);
    > }
    > public insertFailedException()
    > {
    > super();
    > }
    > }


    Compare your Constructor Names to the name of the class...

    Also, usually class names start with an Uppercase letter.



    --

    Whom the gods wish to destroy they first call promising.
    Stefan Schulz, Dec 9, 2004
    #2
    1. Advertising

  3. On Thu, 9 Dec 2004 21:57:25 +0100, stud wrote:

    > Sub: Another simple problem


    Simple problems are best dealt with on a different group.
    <http://www.physci.org/codes/javafaq.jsp#cljh>

    > ERROR:
    > invalid method declaration; return type required
    > invalid method declaration; return type required
    >
    > what's wrong here?


    For resolving problems, start here.
    <http://www.physci.org/codes/javafaq.jsp#exact>

    > class insertFailException extends SQLException
    > {
    > public insertFailedException(String reason)


    This is because you failed to follow-up on the advice that
    Paul van Rossem (and possibly others) pointed out in your
    'Simple Problem' thread.

    --
    Andrew Thompson
    http://www.PhySci.org/codes/ Web & IT Help
    http://www.PhySci.org/ Open-source software suite
    http://www.1point1C.org/ Science & Technology
    http://www.LensEscapes.com/ Images that escape the mundane
    Andrew Thompson, Dec 9, 2004
    #3
  4. stud

    Guest

    The constructor name has to be the same as the class name.
    , Dec 9, 2004
    #4
  5. In article <cpae76$qo$>, stud ()
    dropped a +5 bundle of words...

    > ERROR:
    > invalid method declaration; return type required
    > invalid method declaration; return type required
    >
    > what's wrong here?
    >
    > class insertFailException extends SQLException
    > {
    > public insertFailedException(String reason)
    > {
    > super (reason);
    > }
    > public insertFailedException()
    > {
    > super();
    > }
    > }
    >


    You need either a return type or void for your method.

    public String zoom() {

    }

    public void zoomZoom() {

    }



    --
    Starshine Moonbeam
    mhm31x9 Smeeter#29 WSD#30
    sTaRShInE_mOOnBeAm aT HoTmAil dOt CoM
    Starshine Moonbeam, Dec 9, 2004
    #5
  6. In article <>, Starshine Moonbeam
    () dropped a +5 bundle of words...

    > In article <cpae76$qo$>, stud ()
    > dropped a +5 bundle of words...
    >
    > > ERROR:
    > > invalid method declaration; return type required
    > > invalid method declaration; return type required
    > >
    > > what's wrong here?
    > >
    > > class insertFailException extends SQLException
    > > {
    > > public insertFailedException(String reason)
    > > {
    > > super (reason);
    > > }
    > > public insertFailedException()
    > > {
    > > super();
    > > }
    > > }
    > >

    >
    > You need either a return type or void for your method.
    >
    > public String zoom() {
    >
    > }
    >
    > public void zoomZoom() {
    >
    > }
    >


    However, you're using constructors which don't have the same name as
    your class, which is why Java thinks it's a method.


    --
    Starshine Moonbeam
    mhm31x9 Smeeter#29 WSD#30
    sTaRShInE_mOOnBeAm aT HoTmAil dOt CoM
    Starshine Moonbeam, Dec 9, 2004
    #6
  7. scribbled the following:
    > The constructor name has to be the same as the class name.


    Which is something that has lately struck me as needless. Why not have
    a special keyword for constructors? Such as "new"? For example:

    public class Foobar {
    public new() {
    /* ... */
    }
    public new(int foo, int bar) {
    /* ... */
    }
    }

    There is no loss of information, because every constructor in the same
    class must have the same name anyway.

    --
    /-- Joona Palaste () ------------- Finland --------\
    \-------------------------------------------------------- rules! --------/
    "Remember: There are only three kinds of people - those who can count and those
    who can't."
    - Vampyra
    Joona I Palaste, Dec 10, 2004
    #7
  8. stud

    Chris Smith Guest

    Joona I Palaste <> wrote:
    > Which is something that has lately struck me as needless. Why not have
    > a special keyword for constructors? Such as "new"? For example:
    >
    > public class Foobar {
    > public new() {
    > /* ... */
    > }
    > public new(int foo, int bar) {
    > /* ... */
    > }
    > }


    I certainly don't see a compelling argument against that syntax, and it
    would certainly avoid a couple newbie pitfalls. However, I don't see
    the kind of compelling interest that would result in a language change
    for it after the fact.

    --
    www.designacourse.com
    The Easiest Way To Train Anyone... Anywhere.

    Chris Smith - Lead Software Developer/Technical Trainer
    MindIQ Corporation
    Chris Smith, Dec 10, 2004
    #8
  9. "Joona I Palaste" <> wrote in message
    news:cpcdcu$qo5$...
    > scribbled the following:
    >> The constructor name has to be the same as the class name.

    >
    > Which is something that has lately struck me as needless. Why not have
    > a special keyword for constructors? Such as "new"? For example:
    >
    > public class Foobar {
    > public new() {
    > /* ... */
    > }
    > public new(int foo, int bar) {
    > /* ... */
    > }
    > }
    >
    > There is no loss of information, because every constructor in the same
    > class must have the same name anyway.


    Cool. Of course, the old verbose, less clear notation

    public class Foobar {
    public Foobar () {
    /* ... */
    }

    public Foobar (int foo, int bar) {
    /* ... */
    }
    }

    would still have to be legal. But who would use it
    instead of your suggestion in new code.

    George
    George W. Cherry, Dec 11, 2004
    #9
  10. stud

    wislam Guest

    What if you wanted a method called new() under Foobar obj?

    And I think it might add needless complexity to the compiler & code if
    you used: -
    Car car = new New();
    rather than
    Car car = new Car();
    no?

    How would you initialise the Car object? Same way as before?
    But then the Car() method call doesn't make sense.

    I guess you could do:
    car = new(toyota);

    Which I think is just as confusing (if not more so in the object) if
    you simply used the class name as the constructor.
    --
    Waheed Islam

    http://www.wislam.co.uk/
    wislam, Dec 11, 2004
    #10
  11. wislam <> scribbled the following:
    > What if you wanted a method called new() under Foobar obj?


    > And I think it might add needless complexity to the compiler & code if
    > you used: -
    > Car car = new New();
    > rather than
    > Car car = new Car();
    > no?


    > How would you initialise the Car object? Same way as before?
    > But then the Car() method call doesn't make sense.


    > I guess you could do:
    > car = new(toyota);


    > Which I think is just as confusing (if not more so in the object) if
    > you simply used the class name as the constructor.


    I'm sorry, but you appear to have drawn conclusions from my post I never
    intended. All I was proposing was changing the syntax of the constructor
    declaration. Calling the constructor would remain the exact same as
    before.

    So if you had:

    public class Car {
    public new() {
    /* ... */
    }
    public new(String model, int year) {
    /* ... */
    }
    }

    you would still call it with:
    Car c1 = new Car();
    Car c2 = new Car("Toyota", 1996);

    --
    /-- Joona Palaste () ------------- Finland --------\
    \-------------------------------------------------------- rules! --------/
    "The trouble with the French is they don't have a word for entrepreneur."
    - George Bush
    Joona I Palaste, Dec 11, 2004
    #11
  12. stud

    Tilman Bohn Guest

    On Sat, 11 Dec 2004 16:55:59 +0000, Joona I Palaste wrote:

    [...]
    > public class Car {
    > public new() {
    > /* ... */
    > }
    > public new(String model, int year) {
    > /* ... */
    > }
    > }
    >
    > you would still call it with:
    > Car c1 = new Car();
    > Car c2 = new Car("Toyota", 1996);


    That's even more confusing. If you declare it like a static factory,
    use it like one.

    Car c1 = Car.new();

    Cheers, Tilman

    --
    `Boy, life takes a long time to live...' -- Steven Wright
    Tilman Bohn, Dec 11, 2004
    #12
  13. Tilman Bohn <> scribbled the following:
    > On Sat, 11 Dec 2004 16:55:59 +0000, Joona I Palaste wrote:
    > [...]
    >> public class Car {
    >> public new() {
    >> /* ... */
    >> }
    >> public new(String model, int year) {
    >> /* ... */
    >> }
    >> }
    >>
    >> you would still call it with:
    >> Car c1 = new Car();
    >> Car c2 = new Car("Toyota", 1996);


    > That's even more confusing. If you declare it like a static factory,
    > use it like one.


    > Car c1 = Car.new();


    Why are you bringing static factories into this? This is a proposal for
    a change in *syntax* only. The underlying instantiation mechanisms would
    remain the exact same. All I am saying is that there should be a special
    keyword for constructors so people would not have to type the class
    name again, which I feel is completely redundant.

    --
    /-- Joona Palaste () ------------- Finland --------\
    \-------------------------------------------------------- rules! --------/
    "This is a personnel commuter."
    - Train driver in Scientific American
    Joona I Palaste, Dec 11, 2004
    #13
  14. stud

    Tilman Bohn Guest

    On Sat, 11 Dec 2004 17:56:17 +0000, Joona I Palaste wrote:

    [...]
    > Why are you bringing static factories into this?


    Because that's what it would look like syntactically (except that
    the static and the return type are implicit).

    > This is a proposal for
    > a change in *syntax* only. The underlying instantiation mechanisms would
    > remain the exact same.


    Yes, I understand. The point of contention here was whether this
    syntax would be at least potentially confusing.

    > All I am saying is that there should be a special
    > keyword for constructors so people would not have to type the class
    > name again, which I feel is completely redundant.


    It is. Nobody is denying that (so far). The question is what's
    worse, redundancy or inconsistency. If you want to change syntax,
    why would you do it in a way that increases the potential for
    confusion? With your proposal as it stands, what do you think
    how many questions you would get in here about why a call to
    new() doesn't work?

    Cheers, Tilman

    --
    `Boy, life takes a long time to live...' -- Steven Wright
    Tilman Bohn, Dec 11, 2004
    #14
  15. stud

    Virgil Green Guest

    Tilman Bohn wrote:
    > On Sat, 11 Dec 2004 16:55:59 +0000, Joona I Palaste wrote:
    >
    > [...]
    >> public class Car {
    >> public new() {
    >> /* ... */
    >> }
    >> public new(String model, int year) {
    >> /* ... */
    >> }
    >> }
    >>
    >> you would still call it with:
    >> Car c1 = new Car();
    >> Car c2 = new Car("Toyota", 1996);

    >
    > That's even more confusing. If you declare it like a static factory,
    > use it like one.
    >
    > Car c1 = Car.new();
    >
    > Cheers, Tilman


    Where is it being "declared like a static factory"? The two examples of
    new() are constructors, not methods.

    - Virgil
    Virgil Green, Dec 14, 2004
    #15
    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. nail
    Replies:
    0
    Views:
    1,539
  2. qwerty
    Replies:
    3
    Views:
    9,281
    Scott Allen
    Sep 30, 2004
  3. Maziar Aflatoun
    Replies:
    1
    Views:
    492
    =?Utf-8?B?UGF1bA==?=
    Jan 22, 2005
  4. et
    Replies:
    1
    Views:
    521
    Yunus Emre ALPĂ–ZEN [MCSD.NET]
    Jun 29, 2005
  5. dillon
    Replies:
    1
    Views:
    176
    higabe
    Nov 17, 2003
Loading...

Share This Page