Java中函数内的函数 [英] Function within a function in Java

查看:78
本文介绍了Java中函数内的函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在Java中定义函数内的函数?我正在尝试做类似的事情:

Is it possible to define a function within a function in Java? I am trying to do something like:

public static boolean fun1()
{
  static void fun2()
  {
     body of function.
     fun2();
  }
  return returnValue;
}

但我收到错误非法开始表达

推荐答案

你不能(在Java中它们被称为方法)。

You cannot (and in Java they are called methods).

但是,您可以在方法中定义匿名类,并调用其方法。

You can, however, define an anonymous class inside of a method, and call its methods.

这篇关于Java中函数内的函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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