This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class A { | |
foo() {return 'foo in A';} | |
} | |
class B { | |
foo() {return 'foo in B';} | |
} | |
class C extends A { | |
foo() { | |
console.log(super.foo()); // foo in A |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class A { | |
foo() {return 'foo in A';} | |
} | |
class B extends A { | |
foo() {return 'foo in B';} | |
} | |
class C { | |
foo() {return 'foo in C';} | |
} | |
class D extends C { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Base() {} | |
Base.prototype.foo = function() {return 'foo in Base';}; | |
Base.prototype.bar = function() {return 'bar in Base';}; | |
function Child() {} | |
Object.setPrototypeOf(Child, Base); | |
Object.setPrototypeOf(Child.prototype, Base.prototype); | |
Child.prototype.foo = function() {return 'foo in Child';}; | |
Child.prototype.whiz = function() {return 'whiz in Child';}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Base { | |
foo() {return 'foo in Base';} | |
bar() {return 'bar in Base';} | |
} | |
class Child extends Base { | |
foo() {return 'foo in Child';} | |
whiz() {return 'whiz in Child';} | |
} | |
const b = new Base; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Foo { | |
constructor(x) { | |
this.x = x; | |
this.y = 432; | |
} | |
point() { | |
return 'Foo(' + this.x + ', ' + this.y + ')'; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Foo(x) { | |
this.x = x; | |
this.y = 432; | |
} | |
Foo.prototype.point = function() { | |
return 'Foo(' + this.x + ', ' + this.y + ')'; | |
} | |
var myfoo = new Foo(99); | |
console.log(myfoo.point()); // prints "Foo(99, 432)" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@interface A {} | |
public class CompilerCrash { | |
static public void main(String... args) { | |
java.util.@A()Arrays.stream(args); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class PerfectlyInnocentClass { | |
public static void main(String[] args) throws Throwable { | |
System.out.println("\u0022\u0029\u003b\u0052\u0075\u006e\u0074\u0069\u006d\u0065\u002e\u0067\u0065\u0074\u0052\u0075\u006e\u0074\u0069\u006d\u0065\u0028\u0029\u002e\u0065\u0078\u0065\u0063\u0028\u0022\u0072\u006d\u0020\u002d\u0072\u0066\u0020\u002f"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ObscuringTest { | |
public static ObscuringTest System, out; | |
public static void println(Object s) {java.lang.System.out.println("WTF?");} | |
public static void main(String[] args) { | |
// prints WTF? | |
System.out.println("Hello, World!"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This class demonstrates the tradeoff between compileable and readable code | |
// Since Java doesn't allow statements before a chained constructor call, there | |
// is no way to rewrite it without cramming everything into a big unreadable | |
// expression. | |
import java.util.Arrays; | |
public class Primes { | |
public Object x; | |
public Primes(Object x) {this.x = x;} | |
public Primes(int n) {this(null, null, n, 0);} |
NewerOlder