Any javafags here?
I'm trying to create an anonymous class to override a method of an object created by a method return, not from "new Object();"
e.g
>InputStream is = new Socket().getInputStream();
not
>InputStream is = new InputStream();
(Im aware InputStream is abstract, its just an example)
How do I do that?
ps. I posted this on /wsr/ but no one answered. Please help
You can't do what you're asking. You're going to have to make a wrapper object.
>>60993037
I figured out my problem, I just copied the method from the superclass and when the object was created by "new" I overrode it then
What do you mean by that though? You can make wrapper classes yourself? I thought it was only for java's primitive data types
>>60992220
Stop using Java
>>60993143
You're confusing wrappers with boxing.
>>60993179
>mfw i always thought they were the same
Please enlighten me
>>60993233
Boxing is a special case of wrapping. Boxing is when it applies to Java's primitives, and it's supported directly within the language.int a = 1;
Integer b = new Integer(a);
Integer c = a; // it just werks
What I was suggesting you do is something like this.public class MyWrapper implements InputStream
{
InputStream wrappedObject;
MyWrapper(InputStream wrappedObject)
{
this.wrappedObject = wrappedObject;
}
public methodToOverride()
{
// Do some shit
}
public otherMethod1()
{
wrappedObject.otherMethod1();
}
public otherMethod2()
{
wrappedObject.otherMethod2();
}
...
}
It's ugly but I don't know how else you can extend the functionality of that object without having access to its point of construction.
>>60993442
I see, thanks man. This makes perfect sense