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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:14:14+00:00 2026-05-26T18:14:14+00:00

I am porting Java code in .NET and I am stuck in the following

  • 0

I am porting Java code in .NET and I am stuck in the following lines that (behave unexpectedly in .NET).

Java:

Map<Set<State>, Set<State>> sets = new HashMap<Set<State>, Set<State>>();

Set<State> p = new HashSet<State>();

if (!sets.containsKey(p)) { ... }

The equivalent .NET code could possibly be:

IDictionary<HashSet<State>, HashSet<State>> sets = new Dictionary<HashSet<State>, HashSet<State>>();

HashSet<State> p = new HashSet<State>();

 if (!sets.containsKey(p)) { /* (Add to a list). Always get here in .NET (??) */ }

However the code comparison fails, the program think that “sets” never contain Key “p” and eventually results in OutOfMemoryException.

Perhaps I am missing something, object equality and identity might be different between Java and .NET.

I tried implementing IComparable and IEquatable in class State but the results were the same.

Edit:

What the code does is: If the sets does not contain key “p” (which is a HashSet) it is going to add “p” at the end of a LinkedList>.

The State class (Java) is a simple class defined as:

public class State implements Comparable<State> {

boolean accept;
Set<Transition> transitions;

int number;
int id;

// ...

public int compareTo(State s) {
    return s.id - id;
}

public boolean equals(Object obj) {
    return super.equals(obj);
}

public int hashCode() {
    return super.hashCode();
}
  • 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-05-26T18:14:14+00:00Added an answer on May 26, 2026 at 6:14 pm

    In Java, the list and set implementations override equals etc. The equivalent doesn’t happen in .NET. However, you can create a dictionary using an appropriate equality comparer using HashSet<T>.CreateSetComparer and pass it to the Dictionary constructor like this:

    IDictionary<HashSet<State>, HashSet<State>> sets =
        new Dictionary<HashSet<State>, HashSet<State>>
           (HashSet<State>.CreateSetComparer());
    

    This is assuming that State overrides Equals/GetHashCode and ideally implements IEquatable<State> too.

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

Sidebar

Related Questions

I'm just porting some code over from .net to Java. I've been using the
I'm new to C++ and am porting over code from Java. I have a
I am porting some C# code over to Java. I am having trouble with
I am working on porting an existing VB.Net application to Java, and could not
I recently inherited an e-commerce app (Java/Struts) that I'm porting to Rails. The thing
I'm porting some geolocation java code from http://janmatuschek.de/LatitudeLongitudeBoundingCoordinates#Java (shown below) to python. It can
I'm porting a small snippet of PHP code to java right now, and I
I am porting some C code involving an artificial neural network to Java. I
I have an old personal project written in Java 1.4 that I am porting
I am posting to wordpress in java using xmlrpc successfully using the following code

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.