Another simple problem

S

stud

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();
}
}
 
S

Stefan Schulz

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.
 
A

Andrew Thompson

Sub: Another simple problem

Simple problems are best dealt with on a different group.
ERROR:
invalid method declaration; return type required
invalid method declaration; return type required

what's wrong here?

For resolving problems, start here.
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.
 
S

Starshine Moonbeam

stud ([email protected]) said:
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() {

}
 
S

Starshine Moonbeam

Starshine Moonbeam said:
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.
 
J

Joona I Palaste

(e-mail address removed) 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 ([email protected]) ------------- Finland --------\
\-------------------------------------------------------- rules! --------/
"Remember: There are only three kinds of people - those who can count and those
who can't."
- Vampyra
 
C

Chris Smith

Joona I Palaste said:
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
 
G

George W. Cherry

Joona I Palaste said:
(e-mail address removed) scribbled the following:

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
 
W

wislam

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.
 
J

Joona I Palaste

wislam said:
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);
 
T

Tilman Bohn

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
 
J

Joona I Palaste

Tilman Bohn said:
]
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.
 
T

Tilman Bohn

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
 
V

Virgil Green

Tilman said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top