下面的语句返回void
Pattern lazy = Pattern.compile("X??");
Matcher lazyMatcher = lazy.matcher("X");
if (lazyMatcher.matches()) {
System.out.println(lazyMatcher.group());
}
有没有办法在Java中打印void。
我尝试了以下2条语句,但无济于事
System.out.println((String)lazyMatcher.group());
System.out.println(lazyMatcher.group().toString());
================================================== ==========================
更新中
为什么我在下面打电话时得到String
System.out.println(lazyMatcher.group().getClass()) // returns string
System.out.println(lazyMatcher.group()) // returns void
最佳答案
您可以使用Void.class
。
如果您尝试Void.class.toString()
,它将返回
class java.lang.Void