Discuss / Java / 为啥我仿照String的compareTo,写一个帮助类,省略this,不能用?

为啥我仿照String的compareTo,写一个帮助类,省略this,不能用?

Topic source
public class Main {

	public static void main(String[] args) {
		String[] array = new String[] { "apple", "Orange", "banana", "Lemon" };
		// 请使用忽略大小写排序,并改写为方法引用:
		Arrays.sort(array, helper::compare);
		System.out.println(String.join(", ", array));
	}
}



public class helper {
	private String helpp;
	
	public helper() {
		this.helpp = "aa";
	}
	public int compare(String b) {
		return this.helpp.toLowerCase().compareTo(b.toLowerCase());
	}
}


因为main是按照String排的,不是按照helper排的,改成按照helper排的,就可以了


  • 1

Reply