我有这个C#静态函数下面,需要一个MatchCollection,输入字符串和模式来搜索。 MathCollection通过引用传递,所以为了使用它,我不需要两次运行匹配。我正是如此使用它:有没有Java相当于C#出关键字
MatchCollection matches = new MatcchCollection();
string pattern = "foo";
string input = "foobar";
if (tryRegMatch(matches, input, pattern) { //do something here}
public static boolean tryRegMatch(out MatchCollection match, string input, string pattern)
{
match = Regex.Matches(input, pattern);
return (match.Count > 0);
}
的问题是,是否有可能做到这一点在Java中我已看过一些文章,状态Java是按值传递(保持简单)。默认情况下C#是,但是你可以使用'out'修饰符来使它通过引用传递。我做了很多匹配,这会使编码更简单,否则我必须运行匹配,然后单独测试以获得成功。
Java只知道如何通过值传递,从不参考;所以不,这是不可能的_stricto sensu_ – fge 2014-10-19 01:53:19