Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Another simple problem

Reply
Thread Tools

Another simple problem

 
 
Joona I Palaste
Guest
Posts: n/a
 
      12-11-2004
wislam <(E-Mail Removed)> 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 ((E-Mail Removed)) ------------- Finland --------\
\-------------------------------------------------------- rules! --------/
"The trouble with the French is they don't have a word for entrepreneur."
- George Bush
 
Reply With Quote
 
 
 
 
Tilman Bohn
Guest
Posts: n/a
 
      12-11-2004
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

 
Reply With Quote
 
 
 
 
Joona I Palaste
Guest
Posts: n/a
 
      12-11-2004
Tilman Bohn <(E-Mail Removed)> 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 ((E-Mail Removed)) ------------- Finland --------\
\-------------------------------------------------------- rules! --------/
"This is a personnel commuter."
- Train driver in Scientific American
 
Reply With Quote
 
Tilman Bohn
Guest
Posts: n/a
 
      12-11-2004
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

 
Reply With Quote
 
Virgil Green
Guest
Posts: n/a
 
      12-14-2004
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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Simple VB.Net / webservice requirement (but not simple for me....) Dave E ASP .Net 7 01-11-2006 02:07 PM
Simple Question - Simple Answer? Daniel Frey XML 4 01-12-2005 04:25 PM
Re: Simple Simple question!!! Kevin Spencer ASP .Net 0 06-25-2004 05:25 PM
Re: Simple Simple question!!! ashelley@inlandkwpp.com ASP .Net 0 06-25-2004 04:18 PM
Simple problem with a simple chat script dillon Javascript 1 11-17-2003 11:11 PM



Advertisments