@Override public void transfer(Pipe pipe, Input input, Output output, int number, boolean repeated) throws IOException { output.writeFixed64(number, input.readFixed64(), repeated); }
function Foo() {} var foo = new Foo(); typeof Foo; // == "function" typeof foo; // == "object" foo instanceof Foo; // == true foo.constructor.name; // == "Foo" Foo.name // == "Foo" Foo.prototype.isPrototypeOf(foo); // == true Foo.prototype.bar = function (x) {return x+x;}; foo.bar(21); // == 42
@RunWith(MockitoJUnitRunner.class) public class FooTests { @Mock public Foo<Bar> fooMock; @Test public void testFoo() { when(fooMock.getValue()).thenReturn(new Bar()); } }
@Override public Time readFrom(Input input) throws IOException { return new Time(input.readFixed64()); }
@Override public void writeTo(Output output, int number, Time time, boolean repeated) throws IOException { output.writeFixed64(number, time.getTime(), repeated); }
public class Main{ public static void main(String[] args){ Foo f = new Foo("f"); changeReference(f); // It won't change the reference! modifyReference(f); // It will modify the object that the reference variable "f" refers to! } public static void changeReference(Foo a){ Foo b = new Foo("b"); a = b; } public static void modifyReference(Foo c){ c.setAttribute("c"); } }
@Override public void transfer(Pipe pipe, Input input, Output output, int number, boolean repeated) throws IOException { output.writeFixed64(number, input.readFixed64(), repeated); }
function Foo(){ this.confusing = 'hell yeah'; } var myObject = new Foo();
class Foo { private static volatile Bar bar = null; public static Bar getBar() { if (bar == null) { synchronized(Foo.class) { if (bar == null) bar = new Bar(); } } return bar; } }
@Override public Time readFrom(Input input) throws IOException { return new Time(input.readFixed64()); }
@Override public void writeTo(Output output, int number, Time time, boolean repeated) throws IOException { output.writeFixed64(number, time.getTime(), repeated); }
public Foo acquireFoo(int id) { Foo result = null; if (id > 50) { result = fooService.read(id); } else { result = new Foo(id); } assert result != null; return result; }
function Foo() {} Foo.prototype.y = 11; function Bar() {} Bar.prototype = Object.create(Foo.prototype); Bar.prototype.z = 31; var x = new Bar(); x.y + x.z; // 42
function Foo() {} Foo.prototype = { bar: 123 }; var foo = new Foo(); // foo.bar is 123 foo.bar = 456; // foo.bar is now 456 delete foo.bar; // foo.bar is 123 again.
var obj = new Foo(); (obj instanceof Object); // true (obj instanceof Foo); // true
function Foo(b) { this.baz = b; } Foo.prototype.bar = function bar() { console.log(this.baz); }; var f = new Foo("Charlie"); f.bar(); // logs "Charlie"