Brian Spindler

Greenhorn
+ Follow
since May 17, 2007
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Brian Spindler

passing is 65%, you probably want to be well into the 80% range before taking the exam.
But Float is a subtype of Number, just as Object is a super type of String in the declaration before it and Number is a super type of Integer in the declaration after it. Why the change in behavior for the extends wildcard declaration?
Alright, I'm trying to nail down the rules regarding generics. I have the following class/test cases:



On the line marked "ERROR" I get this from the eclipse workspace:
The method meth(capture#2-of ? extends Number) in the type
Test1<capture#2-of ? extends Number> is not applicable for
the arguments (float)

I would have guessed that because Test1 was parameterized with <Float> that T would resolve to Float. It appears that at this point, the only valid T argument for meth is null. Someone please explain.
John is right, you can demonstrate this by adding just one more method with another different paramter. Once you do this, your class will not compile because the call is indeed ambiguous.

Uncomment the third method to test:



It works the same for varargs and autoboxing, the compiler will compile this just fine:



but as soon as you try to call one of these methods like so:



it fails to compile because it's ambiguous.

HTH.
I think it's becoming much clearer now; it's really about the placement of the [] in regards to the association of the variable.

Thanks all!
can someone explain why b gets a two dimensional declaration in this code:



Nevermind foo and bar; they are my examples to prove the point visually.
changing your pattern to:



will get you what you want. you must specify the end of the regex, you might want to replace the .*? with something more specific.
16 years ago
Thanks Steve, I have NO control so I think I'm going to have to find a happy medium along the lines of your example. Thanks!
16 years ago
yeah, I understand. unfortunately I'm consuming Events from an API which I have no control over.
16 years ago
So I've got an Event listener class that has to handle events. Right now the events are received as an Array so I have :



My issue is that right now the code does something like:



What are some alternative strategies/patterns to this design? All events are certain subclass types and processing is specific per class type but sometimes the same for several (Event1 and Event2 are same but Event3 requires special handling).

Thanks in advance!
16 years ago
Thanks Ranchers! I think I've got enough to go on. At this point I'm leaning towards the FutureTask approach, it seems perfect for my needs. I need to submit N tasks and wait for them to finish processing before I can return the computation.

And thanks Jim for the heads up on the synchronization issues.
Image you have a method doWork() that can take several minutes to complete, you want to spawn a bunch of these from your getWorkDone() method and wait for them to complete then return. Help me to improve the following code:


[ June 16, 2007: Message edited by: Brian Spindler ]
Ahh... now I see where the confusion comes from ( I think)

In the preceding example from K&B the a[x].doStuff() is a method call on the Animal reference array. being defined as:



The compiler can only check that Dog() IS-A animal and since this succeeds the code succeeds, HOWEVER since static does not adhere to polymorphism there is no dynamic linking during runtime of the new Dog().doStuff(), it executes Animal.doStuff().

In the preceding example you are implicitly executing the class method (static) in each constructor.