The ByteBuffer factory method returns a class which implements ByteBuffer.
The ByteBuffer factory method returns a class which implements ByteBuffer. Byte bytes = new byte256; ByteBuffer buf = ByteBuffer. Wrap(bytes); System.out.
Println(buf.getClass()); prints class java.nio. HeapByteBuffer Using ByteBuffer is a relatively advanced tool, you need to understand Java pretty well before you try to extend it IMHO. You can see this by looking at the code.In my IDE you can find it by doing a + on the method.
Public static ByteBuffer wrap(byte array) { return wrap(array, 0, array. Length); } calls public static ByteBuffer wrap(byte array, int offset, int length) { try { return new HeapByteBuffer(array, offset, length); } catch (IllegalArgumentException x) { throw new IndexOutOfBoundsException(); } } BTW: I am a big fan of using ByteBuffer, however you really need to understand what you are doing to use it. Esp when parsing data from a ByteBuffer.
Developers with ten years experience find it tricky to use.
Yeah, I'm gonna end up having to just implement a ByteBuffer in the class, rather than just extending it and inheriting its methods. Too much time and work to go digging around in there trying to figure out which classes do what. – William the Coderer Nov 13 '11 at 8:01.
Nevermind. I see that when a new ByteBuffer is allocated it returns a subclass that uses those abstract methods. The object created is not really a ByteBuffer at all.
Confusing to me. Not sure why they would use this methodology.
The factory pattern -- commonly used to provide a single "constructor" that knows how to make the correct type of an object based on its parameters. – sarnold Nov 13 '11 at 7:40 That should make for some interesting reading... thanks – William the Coderer Nov 13 '11 at 7:41 @William, Its called using a Factory method and Polymorphism. Its a basic principle of Object Orientated design.
– Peter Lawrey Nov 13 '11 at 7:42 The best thing to read is the code, its pretty short for this method. ;) – Peter Lawrey Nov 13 '11 at 7:42 There's so much abstraction in there, I can't tell which classes are just "describing" classes, and which ones are self-reliant and extendable. I don't think they needed to break it down so far.
– William the Coderer Nov 13 '11 at 7:47.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.