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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:19:16+00:00 2026-06-13T23:19:16+00:00

Say I have the function: public Set<String> giveUp() { Set<String> alreadyGuessed = guessed; guessed

  • 0

Say I have the function:

public Set<String> giveUp()
{
    Set<String> alreadyGuessed = guessed;
    guessed = new LinkedSet<String>();

    //fill Guessed with possible words
    anag(currentWord, "");

    //Remove ones already guessed
    Iterator<String> alGuessIterator = alreadyGuessed.iterator();
    while (!alGuessIterator.done())
    {
        guessed.remove(alGuessIterator.get());
        alGuessIterator.advance();
    }

    return guessed;
}

When I call this function and try to store it using a line like:

LinkedSet<String> notGuessed = (LinkedSet<String>)wordGame.giveUp();

Will this always be safe regardless of the internal implementation of the function above? In otherwords, could notGuessed be an ArraySet and it still maintain a perfectly safe cast? Or am I misunderstanding the point of the interface being returned and I am just supposed to have “Set notGuessed” to prevent the need for casting?

My teacher is useless on the matter of questions regarding the class, and will also immediately give me a 0 should I do any unsafe casting.

  • 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-13T23:19:17+00:00Added an answer on June 13, 2026 at 11:19 pm

    That would not be safe, since you can’t be sure of the underlying Type. If you just need to access the methods defined by the Set interface, then you should use:

    Set<String> set = wordGame.giveUp();
    

    If this happens to be a LinkedSet your code would “work”, but if not you will get a ClassCastException. If you need it to be a LinkedSet specifically for any reason, then the giveUp() method should return a LinkedSet explicitly.

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

Sidebar

Related Questions

I have a class say public class CostStore { int DirectorateId { get; set;
Lets say I have some view models set up as follows: public class User
I have a class with property say private string fieldSelectedItem; public string FieldSelectedItem {
Say I have the following: public class MyContainer { public string ContainerName { get;
Say I have this: template<typename T, int X> class foo { public: void set(const
let say i have function like below function doSomethingNow(){ callSomethingInFutureNotExistNow(); } at the moment
Say I have a function that does the following in Vb.net For i as
Say I have a function func(i) that creates an object for an integer i,
Say I have a function foo: (defun foo (x y &rest args) ...) And
Say I have a function foo that I want to call n times. In

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.