Java constructor/method with optional parameters? [duplicate]
问题 This question already has answers here : Closed 6 years ago . Possible Duplicate: Java optional parameters I know that in PHP if you want to call a function with less parameters you declare the function like: function foo(int param1, int param2 = "2"); and now I can call foo(2) and param2 will be set to 2. I tried to do this in a Java constructor but it seems it isn't possible. Is there a way to do this or i just have to declare two constructors? Thanks! 回答1: Java doesn't have the concept of