In 1.8 (JRE 1.8.0_221) this comparison seems to be working where previously comparing two objects with ==
shouldn't be the same? Is this a case of Java optimising away one of the variables or is something else happening?
public class example
{
public static void main(String[] args)
{
String str1 = "hi";
String str2 = "hi";
System.out.println(str1.hashCode());
System.out.println(str2.hashCode());
if (str1 == str2)
{
System.out.println("wut");
}
}
}
Output:
3329
3329
wut