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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T21:35:47+00:00 2026-06-06T21:35:47+00:00

The following code has compilation issues. The compilation error is also attached. Please suggest

  • 0

The following code has compilation issues. The compilation error is also attached. Please suggest solution to the same.

Code:

import java.util.*;

class test{

    int key;

    public static void main(String []args){
        test obj = new test();
        obj.key = 9999;

        LinkedList al = new LinkedList();
        al.add(obj);

        Iterator itr = al.iterator();
        while(itr.hasNext()){
            test temp = new test();
            temp = itr.next();
            System.out.println(temp.key);
        }   
    }
}

Compilation Error :

test.java:17: error: incompatible types

temp = itr.next();
^

required: test

found: Object

  • 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-06T21:35:48+00:00Added an answer on June 6, 2026 at 9:35 pm

    its.next() returns an instance of Object and not the Test

    Make it as follows

    LinkedList<Test> al = new LinkedList<Test>();
    al.add(obj);
    
    Iterator<Test> itr = al.iterator();
    

    So compiler now knows that LinkedList a1 can only hold Test instances so while iterating we will only have instances of Test

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

Sidebar

Related Questions

The following code has concurrency issues. Here inDegVec is a global int * ,
The following is my dining philosophers code and yields a compilation error saying The
I have the following code: SortedSetByDoubleValue<String,Double> set = SortedSetByDoubleValue.create(); It has no compilation errors
How can I make the following code work? During compilation I get an error
Strangely I am getting compilation error in C++ for the following code. class A
So I'm trying to play a video and the following code has worked for
I am generating a simple form with php. The following code has been reduced
I have the following code that has @item.ID from razor: <a href=# id=deleteitem(@item.ID)>Delete</a> When
I have tried the following code but has no effect: Imports system.Runtime.InteropServices <DllImport(UxTheme.DLL, BestFitMapping:=False,
Class 1 has the following code that generates the exception - -(IBAction) searchAllAction: (id)

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.