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

  • Home
  • SEARCH
  • 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 6949991
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:02:06+00:00 2026-05-27T14:02:06+00:00

http://docs.oracle.com/javase/tutorial/java/generics/genmethods.html Quoting from there- A more realistic use of generic methods might be something

  • 0

http://docs.oracle.com/javase/tutorial/java/generics/genmethods.html
Quoting from there-

A more realistic use of generic methods might be something like the following, which defines a static method that stuffs references to a single item into multiple boxes:

public static <U> void fillBoxes(U u, List<Box<U>> boxes) { 
for (Box<U> box: boxes {
  box.add(u); }

}

Here, what does this List<Box<U>> do? How does this work?

Further,

To use this method, your code would look something like the following:

 Crayon red = ...;
 List<Box<Crayon>> crayonBoxes = ...;

The complete syntax for invoking this method is:

Box.<Crayon>fillBoxes(red, crayonBoxes);

I couldn’t understand all these.

  • 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-27T14:02:07+00:00Added an answer on May 27, 2026 at 2:02 pm

    List is a generic collection.
    Box is another generic.

    You can declare Box<Crayon> to construct a Box of Crayons

    List<Box> is a collection of Boxes but Box is generic, need a Type for the box List<Box<Crayon>>.

    Just follow the generic type U. FillBoxes method is static public static <U> void fillBoxes(U u, List<Box<U>> boxes). Static methods doesn’t need a instance, if there is not a instance you can’t declare the type of the box Box<Crayon>, you have to pass the type in the call of the method Box.<Crayon>fillBoxes, knowing that type, the compiler knows that the first parameter in FillBoxes (U u) is a Crayon type and the second is a List of Boxes of Crayons (List<Box<U>> boxes).

    The method will fill a list of Crayon Boxes with red crayons 🙂

    Ufff this was hard for a non Java programmer and non native english speaker…

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

Sidebar

Related Questions

Here is the java package-tree: http://docs.oracle.com/javase/7/docs/api/java/lang/package-tree.html I read a tutorial on Java which stated
Hopefully an easy question. From the example on http://download.oracle.com/docs/cd/E17409_01/javase/tutorial/uiswing/components/combobox.html on Providing a Custom Renderer
According to doc, calendar set() is: http://docs.oracle.com/javase/1.5.0/docs/api/java/util/Calendar.html#set%28int,%20int,%20int%29 set(int year, int month, int date) Sets
I'm currently looking at the EventQueue class on the Oracle website: http://download.oracle.com/javase/1.4.2/docs/api/java/awt/EventQueue.html But I'm
Apparently there is a method that takes a char and returns a char: http://download.oracle.com/javase/6/docs/api/java/lang/Character.html#toLowerCase(char
I'm trying to run the sample code from this Sun tutorial: http://download.oracle.com/javase/6/docs/technotes/guides/rmi/hello/hello-world.html I've copied
http://docs.oracle.com/javase/1.5.0/docs/api/java/util/Timer.html The reason for this question is that I have a timer running at
http://docs.oracle.com/javaee/6/api/javax/xml/rpc/soap/SOAPFaultException.html I am trying to import javax.xml.rpc.soap.SOAPFaultException More details in the Oracle's documentaiton. As
I'm running the following tutorial: http://download.oracle.com/javase/6/docs/technotes/guides/security/jgss/tutorials/BasicClientServer.html I'm getting the following prompts: Connected to server
I read http://download.oracle.com/javase/6/docs/technotes/tools/solaris/keytool.html It says that we can export a CSR file, but no

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.