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 7657129
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T12:56:44+00:00 2026-05-31T12:56:44+00:00

For example, in C#, Foo , Foo<T> , Foo<T1, T2> could have similar semantic

  • 0

For example, in C#, Foo, Foo<T>, Foo<T1, T2> could have similar semantic but are different classes. But in Java, I can’t name classes like that. How to name them? I don’t think Foo, Foo1<T>, Foo2<T1, T2> are appropriate. Any other suggestions?

Actually, I want to design some interfaces which have only one method just like Runnable. But run in Runnable doesn’t have return value and any parameters. I want interfaces like

public interface Runnable<T>{
    void run(T t);
}

public interface Runnable<T, TResult>{
    TResult run(T t);
}

public interface Runnable<T1, T2, TResult>{
    TResult run(T1 t1, T2 t2);
}

And so on. And I think they are better in the same package.

  • 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-31T12:56:46+00:00Added an answer on May 31, 2026 at 12:56 pm

    You can rename them to truly reflect their function:

    BasicFoo
    GenericFoo<T>
    SuperDuperAdvancedFoo<T, U>
    

    you can even declare an interface, say Foo, that provides all the methods every well-behaved Foo should have. Then you implement the interface in different Foos with different type parameters:

    interface Foo<T, U>
    BasicFoo implements Foo<Object, Object>
    GenericFoo<T> implements Foo<T, Object>
    SuperDuperAdvancedFoo<T, U> implements Foo<T, U>
    

    EDIT: working at your examples, the 3 interfaces can really be declare just using one of them:

    public interface Runnable<T1, T2, TResult>{
        TResult run(T1 t1, T2 t2);
    }
    

    and if you don’t want any parameters, you just supply Void whenever necessary. A Void class in uninstantiable, so the only other possibility is to pass or return null. So for example:

    public class MyRunnable implements Runnable<Void, Void, Void>;
    

    creates a method similar to

    void run();
    

    You actually declared

    Void run(Void a, Void b);
    

    but Void in uninstantiable, so you must pass nulls and the function will always return null.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have class foo that contains a std::auto_ptr member that I would like to
I have a string that contains something like this: ##### abc 'foo' /path/to/filename:1 #####
For example: javac Foo.java Note: Foo.java uses unchecked or unsafe operations. Note: Recompile with
Suppose I have a page located at www.example.com/foo , and it contains an <iframe>
I have a PHP5/Zend Framework 1.8.1 web site which is located at: http://www.example.com/foo The
I have a loop created with each, check this example: $('.foo').each(function(i){ //do stuff });
Why can't I set $_SERVER['DOCUMENT_ROOT'] as attribute? see example code class foo { private
Right now I have a script thats http://www.example.com/cgi-bin/foo?var1=A&var2=B Is there a way that I
I have a system that performs operations on lots of Things , these can
I have a set of custom data types that can be used to manipulate

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.