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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T05:01:16+00:00 2026-06-12T05:01:16+00:00

I have a Node<T> (inner) class in Graph<T> class: public class Graph<T> { private

  • 0

I have a Node<T> (inner) class in Graph<T> class:

public class Graph<T> {
    private ArrayList<Node<T>> vertices;
    public boolean addVertex(Node<T> n) {
        this.vertices.add(n);
        return true;
    }
    private class Node<T> {...}
}

When I run this:

Graph<Integer> g = new Graph<Integer>();
Node<Integer> n0 = new Node<>(0);
g.addVertex(n0);

The last line give me error:

The method addVertice(Graph<Integer>.Node<Integer>) in the type Graph<Integer> is not applicable for the arguments (Graph<T>.Node<Integer>)

Why? Thanks in advance?

  • 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-12T05:01:18+00:00Added an answer on June 12, 2026 at 5:01 am

    Your inner class should not override T Since T is already used in outerclass. Consider what can happen if it was allowed. Your outer class would have referred to Integer and Inner class would have referred to another class that too for the same instance.

     public boolean addEdge(Node node1, Node node2) {
            return false;
        }
    
        Graph<Integer> g = new Graph<Integer>();
        Graph<Integer>.Node n0 = g.new Node(0);// As T happens to be integer you can use inside node class also.
    
        public class Node {
            T t;
            Node(T t) {
            }
        }
    

    Or you can use Static Inner class since Static Generics Types are different than instance generic types.

    For More Explanation you can Refer to JLS # 4.8. Raw Types

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

Sidebar

Related Questions

I have this class : public class Stack { private class Node { String
I have a template class ( Node is an inner class within a BST).
Let me explain best with an example. Say you have node class that can
To keep things simple, lets say I have a Node class, each node has
Hi I am writing a linked list data type. I have an inner class
I have next class and try to declare member function which will return pointer
In C# I have an intrusive tree structure that looks like this: public abstract
So I have simple tree: class MyNode { public MyNode Parent; public IEnumerable<MyNode> Elements;
i have been fighting with this code for a few hours now.... Sample Node
I have a table of node likes, which looks roughly like this: lid nid

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.