#Java - Code Snippets for '#ToString' - 2 code snippet(s) found |
|
Sample 1. Using Pojomatic for overriding equals,hashcode and toString methods | |
|
import org.pojomatic.Pojomatic;
import org.pojomatic.annotations.AutoProperty;
@AutoProperty
public class Employee {
public String name;
public int age;
public int salary;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public int getSalary() {
return salary;
}
public void setSalary(int salary) {
this.salary = salary;
}
@Override
public int hashCode() {
return Pojomatic.hashCode(this);
}
@Override
public boolean equals(Object other) {
return Pojomatic.equals(this, other);
}
@Override
public String toString() {
return Pojomatic.toString(this);
}
}
|
|
Like Feedback pojomatic toString method toString hashcode method equals method overrding equals method overriding hashcode method overrding tostring method @autoproperty pojomatic autoproperty |
|
|
Sample 2. Method that will remove given character from the String | |
|
private static String removeChar(String str, char c) {
if (str == null)
return null;
return str.replaceAll(Character.toString(c), "");
}
|
|
Like Feedback string string.replaceall Character.toString |
|
|