Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 575371
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T13:56:00+00:00 2026-05-13T13:56:00+00:00

In the sun extended RMI tutorial, they have some interesting code which implements a

  • 0

In the sun extended RMI tutorial, they have some interesting code which implements a ‘compute engine’, using RMI they pass the function over to the compute engine, which then returns the results. More details here: http://java.sun.com/docs/books/tutorial/rmi/designing.html

This means that at the onset the return type is not known, so they use the following work-around:

package compute;

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

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

and
package compute;

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

how is this able to work? what property of java does implement?
what could i read up more about this?

thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T13:56:00+00:00Added an answer on May 13, 2026 at 1:56 pm

    how does this code work (return type undefined)

    This code is using generics, and the T is called a generic type parameter. The return type isn’t really “undefined”. Instead, we say it’s parameterized: the return type will eventually be replaced by a real, concrete type. That is, the return type is defined by whatever kind of Task<T> you’ve created.

    You can think of this like a function which accepts a particular type and generates a specialized version of each Task<T> that is requested. (That’s not quite what happens under the covers — in fact, ultimately the compiler discards the information about a generic object’s runtime type — but a more in-depth treatment is probably outside the scope of this StackOverflow answer.)

    Under the covers, when you compile this code, the Java compiler will make sure that no rules are broken about the creation of Task<T>‘s and the relationship to its execute() methods. For example, the compiler will flag this as illegal:

    public class Boat { ... }
    public class Car { ... }
    
    public CarFactory implements Task<Car> {
      public Boat execute() { ... } // Error! A Boat is not a Car.
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

From Sun's Java Tutorial , I would have thought this code would convert a
The sun grid engine defaults to csh, and you have to put this: #$
Using com.sun.org.apache.xml.internal.serialize.XMLSerializer and com.sun.org.apache.xml.internal.serialize.OutputFormat causes some errors when compiling using java 1.6. The solution
I have implemented simple com.sun.net.httpserver.HttpServer application using one of examples in the internet. Server
Using latest JAXB (Sun) and have a hierarchy of schemas that use import directives
Using Sun Glassfish Enterprise server v2.1.1 I am using alternatedocroot via sun-web.xml for my
I read in Sun official documentation (or Sun online tutorial) about dotted naming for
I found this Is Sun Java really necessary for using Android SDK on Ubuntu
I was trying to sun some javascript on my html page but it doesn't
Using the stock Sun 1.6 compiler and JRE/JIT, is it a good idea to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.