如何在子程序中声明默认调用变量 [英] How to declare default call variables in a sub

查看:104
本文介绍了如何在子程序中声明默认调用变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C#中,我可以编写类似
的子代码

In C# i can write a sub like

public void example(Boolean closeControlOnFinish = true){
}


其中closeControlOnFinish默认为true,因此我可以调用example();而不必调用example(true);.

如何在Java中复制此内容?以下无效.另外请注意,该代码在公共类Download中,扩展为


Where closeControlOnFinish is by default true so i can call example(); without having to call example(true);.

How do I replicate this in java? The following doesn''t work. Additionally note that the code is in public class Download extends

java.awt.Panel.

public Download(Boolean closeControlOnFinish = true) {
}

推荐答案

Java中没有完全相同的功能,即使C#是在v.4中引入的.

要获得合理的解决方法,请查看以下答案:
http://stackoverflow.com/questions/965690/java-optional-parameters [ ^ ].

—SA
There is no exact same feature in Java, and even if C# it was introduced in v.4.

For a reasonable work-around, take a look at this answer:
http://stackoverflow.com/questions/965690/java-optional-parameters[^].

—SA


这篇关于如何在子程序中声明默认调用变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆