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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:30:25+00:00 2026-06-17T08:30:25+00:00

I am currently working on a project where I have to make some method

  • 0

I am currently working on a project where I have to make some method generic (to make the code more readable).

The projects has two classes: Box and MyList.
The constructor for ‘Box’ accepts to generic parameters; the constructor for ‘MyList’ only one.

public class Box<A, B> {}

That is the class for the box.

public class MyList<T> {}

And thats the class for MyList.

In the class ‘Box’ I have a method that looks like this:

public static MyList enclose (Box <MyList <Integer, String>> t) {
// Here comes some code that is not important right now.
}

What I want now, is to make this method generic so that it not only takes in parameters like a Box. Has anyone an idea?

  • 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-06-17T08:30:26+00:00Added an answer on June 17, 2026 at 8:30 am

    It is not completely clear what you want to do, and the number of generic parameters do not match your classes but maybe this does the work?

    public <T> static MyList<T> enclose (Box <MyList <T>, String> t) {
    // Here comes some code that is not important right now.
    }
    

    Or if you want to avoid talking about MyList, maybe this:

    public <T> static T enclose (Box <T, String> t) {
    // Here comes some code that is not important right now.
    }
    

    The second version has the type of the first generic parameter of the Box object as its return type…

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

Sidebar

Related Questions

I am currently working on a project where I have code that looks like
I have a MVC 4 project I am currently working on and need some
I am currently working on a project in JAVA where I have to make
I am currently working on some web dev project in Java, i have implemented
I am currently working on a project about calculations.I have done the main part
I am currently working on android project where I want to have a text
I am currently working on an android project and I have an activity, lets
I am currently working on grails project. I have created eight different plugins. Each
Im currently working on a grizzly, spring and jersey project and i have encountered:
Hello Ruby/Rails/Merb developers! Im currently working on a web project that will have a

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.