Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

does not appear on the righthand side of an assignment, but is used as a argument to a method invocation. Why does it happen?

0
Posted

does not appear on the righthand side of an assignment, but is used as a argument to a method invocation. Why does it happen?

0

For the type inference of new Callable <> () there is neither a constructor argument nor an assignment context. Hence the compiler infers that the missing type parameter of Callable is type Object . For the type inference of new FutureTask <> (new Callable <> ()) there is a constructor argument, namely Callable , which leads to the conclusion that the missing type parameter of FutureTask is type Object as well. This makes for a type mismatch when assignment compatibility is checked and an error message is emitted. The surprise perhaps is that the compiler does NOT consider the type information Future of the lefthand side expression of the assignment. It always takes a look at the constructor arguments first. The constructor of the FutureTask has an argument of type Callable and it permits a successful type inference the result of which is FutureTask ; the Future on the lefthand side is ignored for type inference because it is not needed for a success

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123