Folge dem Video um zu sehen, wie unsere Website als Web-App auf dem Startbildschirm installiert werden kann.
Anmerkung: Diese Funktion ist in einigen Browsern möglicherweise nicht verfügbar.
PS: Die Frage ist schon knapp ein Jahr alt..
package de.tutorials;
import java.util.Date;
public class AnnotationExample {
private static String supUnused1 = "unused";
private static String supDeprecation1 = "deprecation";
private static final String supUnused2 = "unused";
private static final String supDeprecation2 = "deprecation";
private static final String[] suppressArray = { "unused", "deprecation" };
public static void main(String[] args) {
// Test 1
@SuppressWarnings( { "unused", "deprecation" })
new Date().getDay();
// Test 2
@SuppressWarnings( { "unused", "deprecation" })
int a = new Date().getDay();
// Test 3
@SuppressWarnings( { supUnused1, supDeprecation1 })
int b = new Date().getDay();
// Test 4
@SuppressWarnings( { supUnused2, supDeprecation2 })
int c = new Date().getDay();
// Test 5
@SuppressWarnings(suppressArray)
int d = new Date().getDay();
}
}
package de.tutorials.training;
import java.lang.reflect.Constructor;
public class SneakyObjectConstruction {
public static void main(String[] args) throws Exception {
try {
System.out.println(X.class.newInstance());
} catch (Throwable t) {
System.out.println(t);
}
try {
Constructor<?> ctor = X.class.getDeclaredConstructor();
ctor.setAccessible(true);
System.out.println(ctor.newInstance());
} catch (Throwable t) {
System.out.println(t);
}
//TODO insert your approach here :)
}
static class X {
private int i = 1;
private X() {
if(i == 1){
throw new IllegalStateException("i is 1");
}
}
}
}
package de.tutorials.training;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
// Our test driver
public class SneakyObjectConstruction {
public static void main(String[] args) throws Exception {
try {
System.out.println(X.class.newInstance());
} catch (Throwable t) {
System.out.println(t);
}
try {
Constructor<?> ctor = X.class.getDeclaredConstructor();
ctor.setAccessible(true);
System.out.println(ctor.newInstance());
} catch (Throwable t) {
System.out.println(((InvocationTargetException)t).getTargetException());
}
// Some working approaches :)
//ReflectionFactory
try {
sun.reflect.ReflectionFactory reflectionFactory = sun.reflect.ReflectionFactory.getReflectionFactory();
Constructor<X> ctor = reflectionFactory.newConstructorForSerialization(X.class, Object.class.getDeclaredConstructor());
System.out.println("ReflectionFactory: " + ctor.newInstance());
} catch (Throwable t) {
System.out.println(t);
}
//Unsafe
Field f = sun.misc.Unsafe.class.getDeclaredField("theUnsafe");
f.setAccessible(true);
sun.misc.Unsafe u = (sun.misc.Unsafe)f.get(null);
System.out.println("Unsafe: " + u.allocateInstance(X.class));
//Method by Dr. Heinz Kabuts :)
//See http://www.javaspecialists.eu/archive/Issue032.html
System.out.println("Heinz Kabutz: " + Y.make());
}
static class X {
private int i = 1;
private X() {
if(i == 1){
throw new IllegalStateException("i is 1");
}
}
}
static class Y extends X {
private static Y y;
static Y make() {
try {
new Y();
} catch (Exception ex) {
try {
synchronized (Y.class) {
while (y == null) {
System.gc();
Y.class.wait(100);
}
}
} catch (InterruptedException ie) {
return null;
}
}
return y;
}
@Override
protected void finalize() throws Throwable {
synchronized (Y.class) {
y = this;
Y.class.notify();
}
}
}
}
java.lang.IllegalAccessException: Class de.tutorials.training.SneakyObjectConstruction can not access a member of class de.tutorials.training.SneakyObjectConstruction$X with modifiers "private"
java.lang.IllegalStateException: i is 1
ReflectionFactory: de.tutorials.training.SneakyObjectConstruction$X@459189e1
Unsafe: de.tutorials.training.SneakyObjectConstruction$X@2f9ee1ac
Heinz Kabutz: de.tutorials.training.SneakyObjectConstruction$Y@24c21495