Functions are not first class citizens in Java, meaning that you cannot treat them as you would any regular data type such as a double. Java does however have a work-around using anonymous classes (or lambdas which are syntactic sugar) if you want to use a function as an argument to another function. See: What is a first class citizen function?
Videos
What is Encapsulation in Java?
What are the Rules for Functional Interface?
What is Knowledge Pass, and how does it work?
Functions are not first class citizens in Java, meaning that you cannot treat them as you would any regular data type such as a double. Java does however have a work-around using anonymous classes (or lambdas which are syntactic sugar) if you want to use a function as an argument to another function. See: What is a first class citizen function?
I have no experience with swift; however I use Java fairly frequently (I am mainly a c and c++ guy now days), so I will try to take a stab at this question.
Java Variables
In Java there are types for variables such as int, double, long, and float. The reason you declare a variable type in Java is to tell the compiler how much memory to set aside to store the variable. Declaring variable type also tells the compiler how to manage the variable for instance adding two strings concatenates them where adding two numbers numerically adds them.
Java Functions
In Java when declaring a function you need to tell the compiler what type of value the function will return. For instance
int add(int num1, int num2){
return num1 + num2;
}
returns an integer value, while
void doSomething(){
......
}
does not return anything. In general, functions can be declared of any type that a variable can be declared as. This concept applies to many languages (c and c++ are a couple major examples). I hope this answers your question.