Basically I have three variables a,b and c. The variables have certain relationship among them. I need to store the variables in a HashSet so that each variable will be different and there wont be any redundancy.
Java way:
In java I just create a custom class, override hash and equal methods in that custom class and I will be done.
HashSet<CustomClass> hSet = new HashSet<CustomClass>();
Scala way (Scala newbie):
Introduction to Sets and Maps for Scala
Here I am confused to choose between a trait , class and an object. Obviously at the first look I cannot have trait and class assigned to a var / val (Please let me know if the above can be done). So object is the way to go.
object State {
var a: Int;
var b: Int;
var c: Int;
}
Question 1: How should I define a custom (class/trait/object) HashSet?
Normal HashSet declaration in Scala: var hSet = new HashSet();
Question 2: How to assign value to the new object? for example,
var newState = State;
newState.a = 100;
hSet.add(newState);
Error : type mismatch; found : Int(100) required: Int.type
Thank you
case class
for your elements. – dmitry