java的错误代码_编译时的简单Java错误代码

我想在代码下面运行。它给我错误

The operator + is undefined for the argument type(s) String, void

public class CompStrings{

String s1=null;

String s2=null;

public void testMethod(){

s1 = new String("Hello");

s2 = new String("Hello");

String str3="abc";

String str4 ="abc";

/**

* ==

*/

if(str3==str4){

System.out.println("str3==str4 is true");

}else{

System.out.println("str3==str4 is false");

}

if(str3.equals(str4)){

System.out.println("str1.equals(str2) is true");

}else{

System.out.println("str1.equals(str2) is false");

}

System.out.println(s1.hashCode());

System.out.println(s2.hashCode());

System.out.println(s1 + " equals " + s2 + " -> " +

s1.equals(s2));

System.out.println(s1 + " == " + s2 + " -> " + (s1 == s2));

/*Integer i1 = new Integer(10);

Integer i2 = new Integer(10);

System.out.println(i1.hashCode());

System.out.println(i2.hashCode());

1)String s1="hello";

String s2="hello";

2)String s1 = new String("Hello");

String s2 = new String("Hello");

3)String s1="hello";

string s2=s1;

**/

}

public static void main(String argv[]){

CompStrings obj= new CompStrings();

// \System.out.println("Calling My Method"+ obj.testMethod());

System.out.println("Hashcode for emp1 = " + obj.testMethod());// Here it gives Error

}

public boolean equals(Object o){

String s = (String) o;

if (s1.equals(s) ){

return true;

}else{

return false;

}

}

public int hashCode(){

return s1.hashCode();

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值