Discovering a java object's construtor

Associate
Joined
19 Jun 2006
Posts
162
Location
Swansea, Wales
I have a Java class with two constructors. One accepts a string and 2 vectors, the other accepts a string and a vector.

Code:
/* Constructor 1 */
public P(String[] pSL, Vector pHd) {
}

/* Constructor 2 */
public P(String[] pSL, Vector pHd, Vector pBd) {
}

My question is simply this. How can I tell what constructor has been used to create my object?

I need to know because I only want to call a certain function if the second constructor has been used.
 
Dj_Jestar said:
then only call the method from within the second constructor :\

A little more explanation may be necessary...

Class Sniff sniffs a packet from the network and casts it as an object of type packet.

A method then analyses this packet and uses one of the two constructors to make an object based on the packet contents.

Sniff then calls a print function for the two or three parts of the object. If no third part has been created then obviously an error is thrown.

Thinking about it i could just catch the error and do nothing but is this good practice?
 
Sorted now. Stupid question really now I think about it but I'd been coding all day yesterday and I guess I was just having one of those coders block moments!

Dfhaii said:
:( I was expecting some fun with reflection when I read the thread title.

What the hell is reflection!? Is it as exciting as it sounds?
 
Back
Top Bottom