Java: how this code works (return type undefined)

In the advanced RMI tutorial on the sun, they have an interesting code that implements the "computing engine", using RMI, they pass a function to the calculation processor, which then returns the results. More details here: http://java.sun.com/docs/books/tutorial/rmi/designing.html

This means that the return type is unknown at the beginning, so they use the following workspace:

package compute;

import java.rmi.Remote;
import java.rmi.RemoteException;

public interface Compute extends Remote {
    <T> T executeTask(Task<T> t) throws RemoteException;
}

and batch calculation;

public interface Task<T> {
    T execute();
}

how can it work what java property implements? What could I learn more about this?

thank!

+3
source share
5 answers

how this code works (return type undefined)

generics, T . "undefined". , : . Task<T>, .

, Task<T>. ( , - , , , , , StackOverflow.)

, , Java , Task<T> execute(). , :

public class Boat { ... }
public class Car { ... }

public CarFactory implements Task<Car> {
  public Boat execute() { ... } // Error! A Boat is not a Car.
}
+2

Java Generics.

, Angelika Langer FAQ .

+2

T. -, Compute, executeTask. - , . , :

Object executeTask(Task<Object> t){...}
Integer executeTask(Task<Integer> t){...}

.

0

generics, : , Java RMI.

" " ( , SecurityManager, ), .

0

Source: https://habr.com/ru/post/1730259/


All Articles