开发者

VB.NET -v- Java: Switch statements & optional parameters

Is th开发者_如何学运维ere an equivalent in Java to VB.NET's optional parameters?

Also is it possible to switch on anything other than integers in Java?

Thanks.


The simple answer is no there is no direct equivalent in Java of VB.NET's optional params. In Java the practice is to "overload" methods. This means that you write a number of different method headers with similar logic but with different passing parameters defined. The Java VM will select the appropriate method based on what parameters are passed in when called.

As for switch statements no in Java switch statements only work with integers natively but there are a few 3rd party libraries out there that provide extended switch functionality. Defo worth a Google!

Check these out also: Java optional parameters and: Why can't I switch on a String?.

They give a good explanation.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜