Object constructors

"Shay Harding" <sharding-YCNXYxaMkU/[email protected]> Mon, 24 Mar 2003 11:23:39 -0700
Newsgroups gmane.comp.lang.moto.devel
Message-ID <000001c2f232$7e202e40$7500000a@ccbill22ms668m>
Ok, let's say I have the following:


class A{
  A(String x){

  }

  A(String x, boolean y){

  }
}

Works no problem since each constructor has a different number of args. When
I try to declare:

class A{
  A(String x){

  }

  A(boolean x){

  }
}

it tells me I am redefining A() since they each have 1 arg. Is there no way
to define different constructors with the same number of args, but of
different types? This happens when I want one constructor to take say a
"String" and another to take an "Object" I can derive the "String" from:

class A{
  A(String x){

  }

  A(Object o){
    A(o.getString());
  }
}


One use I can think of is if I have an object that can parse XML. I want to
be able to pass XML data (as a String) into it, but I also want to be able
to pass an XMLStream object where I can read the data (when the document is
too big to pull into available memory).



Shay

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.463 / Virus Database: 262 - Release Date: 3/17/2003