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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:28:29+00:00 2026-06-15T10:28:29+00:00

How do I throw and UnsupportedOperationException on a method? So if I have an

  • 0

How do I throw and UnsupportedOperationException on a method? So if I have an Iterable object and I’m trying to disallow the remove method for that object.

In the method below I’m returning an iterable object whose iterator’s remove I need to disable by throwing an UnsupportedErrorException. Can I do this within the body of the method or how so?

  public Iterable<String> getInNodes (String destinationNodeName)  {
  if (!hasNode(destinationNodeName))
      return emptySetOfString;
  else {
  for(String e : nodeMap.get(destinationNodeName).inNodes)
  {
      emptySetOfString.add(e);
  }
  return emptySetOfString;
  }
}
  • 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-15T10:28:30+00:00Added an answer on June 15, 2026 at 10:28 am

    Try this.

    @Override
    public void remove() {
       throw new UnsupportedOperationException();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How does Iterator throw ConcurrentModificationException when we are adding some object after current node
I want to throw an exception in my constructor so that I don't have
ArrayList 's list iterator does implement the remove method, however, I get the following
I'm trying to create a b-tree class that implements the collection interface shown below.
I have a class that has an explicit initialization method and some other methods
How come I can have public void someMethod() { throw new UnsupportedOperationException(); } but
I'm trying to write an implementation of iterator so that I can call it
// // To Throw void PrintType(object obj) { if(obj == null) { throw new
I need to throw 404 error in module. Or may be there are any
Would you throw an IllegalStateException if: A method is unable to do its job

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.