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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T15:55:10+00:00 2026-06-13T15:55:10+00:00

Using Java: I didn’t want to waste peoples time and post this here, but

  • 0

Using Java:
I didn’t want to waste peoples time and post this here, but my googling-skills have failed me and I can’t find the answer. I was looking through some supplied code and they used

public static <E> void printTree(TwoFourTree<E> tf)

(For reference we are converting from a Red-Black tree to a Two-Four Tree). When I first approached this problem I would use instead of and not even include in the initial method declaration of public static void. However I ran into issues, and throwing in this <E> solved all my problems, despite using <Integer> instead of <E> everywhere else.

So my question is, can someone please explain to me what exactly the <E> does in

public static <E> void
  • 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-13T15:55:12+00:00Added an answer on June 13, 2026 at 3:55 pm

    This is a Java feature known as Generics.

    Why would you want to use Generics? Well, the following gives one scenario where they are useful. Back in the “bad old days”, if you wanted to have a class that could work with any objects you had to declare all it’s interfaces in terms of objects, e.g.

    public class MySuperList
    {
        public void Add(object a) { }
    }
    

    However, this sucks, because you get no type-safety – you could write code like the following:

    // Your code
    MySuperList list = new MySuperList();
    cars.Add(new Car("Ford Mondeo"));// Works
    cars.Add(new Fish("Herring")); // Works - which is a shame as a Fish is not a car!
    

    Generics fixes this, by allowing you to strongly-type your class, but in a generic manner. For example:

    public class MySuperList<T>
    {
        // Add method will only accept instances of type T.
        public void Add(T a) { }
    }
    
    // Your code
    MySuperList<Cars> list = new MySuperList<Cars>();
    cars.Add(new Car("Ford Mondeo"));// Works
    cars.Add(new Fish("Herring")); // Compile-time error.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've spent the last year learning and using Java in university but we didn't
So, if you are writing a website using Java and JSP's and didn't want
I have searched about this matter a lot but, I didn't get a proper
How can I merge two wav files using java? I tried this but it
Using Java (1.6) I want to split an input string that has components of
Using Java sockets, I made a simple server. This works because it sends data
I'm using java.awt.Robot for integration tests of my Swing application, but I'm having trouble
For the last two years I have been using Java and NetBeans, where all
Using Java, I get this error when attempting to connect to a mysql database:
I want to take a video file and encrypt it using java. For now

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.