Eğer bu temel bir şey olmasından dolayı özür dilerim ama java'yı başlatıyorum ve bu herhangi bir ödev değil, neden basit test programım başarısız oluyor?HashMap acemi programcı, neden programımda false döndürüyor içerdi
static public class pair
{
public int x;
public int y;
public pair(int a , int b)
{
x = a;
y = b;
}
}
public static void main(String args[])
{
HashMap<pair,Integer>m = new HashMap<pair,Integer>();
m.put(new pair(1,2), 3);
if(m.containsKey(new pair(1,2)))
{
System.out.println("is there " + m.get(new pair(1,2)));
}
}
Bu benzer bir soru: http://stackoverflow.com/questions/12774723/calling-containskey-on-a-hashmap-with-custom-class?rq=1 –
Eğer "eşittir" geçersiz kılmadıysanız ve 'hashCode' sonra her nesnenin farklı olduğunu söylüyorsunuz. –
Sadece Java ile başlıyorsanız, Java kod stili https://google.github.io/styleguide/javaguide.html –