Function within a function in Java [duplicate]

The reason you cannot do this is that functions must be methods attached to a class. Unlike JavaScript and similar languages, functions are not a data type. There is a movement to make them into one to support closures in Java (hopefully in Java 8), but as of Java 6 and 7, it’s not supported. If you wanted to do something similar, you could do this:

interface MyFun {
    void fun2();
}

public static boolean fun1()
{
  MyFun fun2 = new MyFun() {
      public void fun2() {
          //....
      }
  };
  fun2.fun2();
  return returnValue;
}

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)