package tk.lslayer.temp;
public class NullComparator {
public Integer someField = null;
@Override
public boolean equals(Object obj) {
if (obj == null && someField == null) return true;
if (obj != null && obj instanceof NullComparator) {
return ((NullComparator) obj).someField == someField ?
true : false;
} else return false;
}
public static void main(String[] args) {
NullComparator comparator1 = new NullComparator();
if (comparator1 == null)
System.out.println("!= null");
if (comparator1.equals(null))
System.out.println(".equals(null)");
}
}
public class Parent {
private String valueForPass = "some value";
protected final String getValueForPass() {
return valueForPass;
}
}
public class Child extends Parent {
private String myOtherValue = super.getValueForPass();
}
public static Status getStatus(Exception e) {
if (e.getClass.equals(MyCoolUnautorisedException.class)) {
return Status.UN_AUTHORIZED;
}
// More Exception handlers
return null; //If something gone wrong
}
//Main code
try {
// some logic
} catch (Exception e) {
// etc LOGGER.error(e);
return Response.status(SomeStatusHandler.getStatus(e)).build();
} finally {
//Here we go!
}
x.format("Ваше название %s, Ваше %d число, Ваш комментарий %s", b, a, c);
x.flush()
x.close();
package tk.lslayer.temp;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.util.Formatter;
import java.util.Scanner;
public class Main {
static Formatter x;
static Scanner scn;
public static void main(String[] args) {
try{
x = new Formatter(new BufferedWriter(new FileWriter("src//1.txt", true)));
scn = new Scanner(System.in);
System.out.println("Число?");
int a = (int)Double.parseDouble(scn.next());
System.out.println("Название?");
String b = scn.next();
System.out.println("Комментарий?");
String c = scn.next();
x.format("Ваше название %s, Ваше %d число, Ваш комментарий %s", b, a, c);
x.flush();
x.close();
} catch (Exception e) { }
}
}