Re: Another simple problem

From: Joona I Palaste (palaste_at_cc.helsinki.fi)
Date: 12/11/04


Date: 11 Dec 2004 16:55:59 GMT

wislam <wislam@gmail.com> 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 (palaste@cc.helsinki.fi) ------------- Finland --------\
\-------------------------------------------------------- rules! --------/
"The trouble with the French is they don't have a word for entrepreneur."
   - George Bush


Relevant Pages

  • Re: (LONG) Student Question: constructors and setMethods
    ... specify in the constructor. ... You can't drive the car factory to school -- you need to ... The "method" used to set the radio station to 1020 is ...
    (comp.lang.java.help)
  • Re: compile error about auto_ptr
    ... This question, about the rationale of the standard, would be better ... neither intuitive nor very practical (in particular, a templated constructor does not qualify as a formal copy constructor). ... It's just an example of adopting a special case descriptive term as a formal name for a slightly more general category. ... car, a car used to transport goods, essentially a van) is given a very strict definition as a formal term, with the result that some ordinary cars have sub-optimal designs in order to be formally classified as ...
    (microsoft.public.vc.language)
  • Re: Clean up after exception thrown in constructor
    ... I have a class hierarchy where the constructor of a child class can throw an exception, while the constructor of the parent class has some side-effects. ... public void remove{// called when car is no longer used ...
    (comp.lang.java.programmer)
  • Re: Clean up after exception thrown in constructor
    ... I have a class hierarchy where the constructor of a child class can throw an exception, while the constructor of the parent class has some side-effects. ... public void remove{// called when car is no longer used ...
    (comp.lang.java.programmer)
  • Clean up after exception thrown in constructor
    ... I have a class hierarchy where the constructor of a child class can throw an exception, while the constructor of the parent class has some side-effects. ... public void remove{// called when car is no longer used ...
    (comp.lang.java.programmer)