(int) ((char) -1) == ... (short) ((int) ((char) -1)) == ...
int x = ...;
if (x! = 0 && x == -x) {
System.out.println ("COOL");
}
double x = ...;
if (x! = x) {
System.out.println ("COOL");
}
public class Test {
static int a () {print ("a"); return 1; }
static int b () {print ("b"); return 1; }
static int c () {print ("c"); return 1; }
static void print (String s) {System.out.println (s); }
public static void main (String [] p) {
int d = a () + b () * c ();
print ("" + d);
}
}
public class Test {
static int a () {print ("a"); return 1; }
static int b () {print ("b"); return 1; }
static int c () {print ("c"); return 1; }
static void print (String s) {System.out.println (s); }
public static void main (String [] p) {
if (a () == b () || a () == c ()) {
print ("d");
}
}
}
public class Test {
static int a () {print ("a"); return 1; }
static int b () {print ("b"); return 1; }
static int c () {print ("c"); return 1; }
static void print (String s) {System.out.println (s); }
public static void main (String [] p) {
try {
if ((a () + b ()) / (a () - b ()) + c () == a ()) {
print ("d");
}
} catch (Throwable e) {
}
}
}
class BasicExcept extends RuntimeException {
private int b = 10;
public BasicExcept () {
b = 15;
throw this;
}
{
b = 5;
}
public int getB () {
return b;
}
public String toString () {
return "Superclass";
}
}
class Except extends BasicExcept {
private int a = 10;
public Except () {
super ();
a = 15;
}
{
a = 5;
}
public int getA () {
return a;
}
public String toString () {
return "Subclass";
}
}
public class Test {
public static void main (String [] args) {
try {
new Except ();
System.out.println ("No exception");
} catch (Except e) {
System.out.println ("Exception occured! A =" + e.getA ()
+ ", B =" + e.getB ()
+ ", toString () =" + e.toString ());
}
}
}
class TryExcept extends RuntimeException {
private String s;
static {
init ();
}
public TryExcept () {
s = "hahaha";
}
private static void init () {
throw new TryExcept ();
}
public String get () {
return s;
}
}
public class Test {
public static void main (String [] args)
{
for (int i = 0; i <2; i ++) {
try {
new TryExcept ();
} catch (Throwable e) {
System.out.println ("e =" + e);
if (e.getCause () instanceof TryExcept) {
TryExcept ex = (TryExcept) e.getCause ();
System.out.println ("e instanceof"
+ TryExcept.class.getName ()
+ ", s =" + ex.get ());
}
}
}
}
}
Source: https://habr.com/ru/post/89580/
All Articles