This discussion is archived
0 Replies Latest reply: Jul 28, 2013 12:59 AM by 800839 RSS

Java generic template param for multiple operations

800839 Newbie
Currently Being Moderated

Hi,

 

  I have written 2 constructors (overloaded constructors) to serve to 2 different operations as shown below:-

 

Class ShippingDetails extends BaseDetails
{

  public ShippingDetails(shippingRequest){
   super(shippingRequest);

    }

}

Class OrderDetails extends BaseDetails
{
public OrderDetails(orderDetails){
   super(orderDetails);
}

}

Class BaseDetails
{

  public BaseDetails(orderDetails){

  // logic for orderDetails
   
}

public BaseDetails(shippingDetails) {

  //logic for shippingDetails

}

}

}

now I want to make it generic by using a single constructor in the BaseDetails.java which will serve any request, hence I thought of using generic parameter with "T". I can go with boolean as well but here the number of request will grow hence thought of using the generic template param.

Please let me know how we can go about it for the above code? Please clarify.

 

Thanks.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points