Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 481002

Summary: "Cannot infer type arguments" with nested ternary
Product: [Eclipse Project] JDT Reporter: Chris Cooper <chris.cooper>
Component: CoreAssignee: JDT-Core-Inbox <jdt-core-inbox>
Status: CLOSED WONTFIX QA Contact:
Severity: normal    
Priority: P3    
Version: 4.5.1   
Target Milestone: ---   
Hardware: PC   
OS: Windows 10   
Whiteboard: stalebug

Description Chris Cooper CLA 2015-10-29 10:21:10 EDT
Compiles fine using JDK 1.8 but Eclipse (4.5, 4.5.1) reports the following as an error:

//---
import java.util.function.Function;

public class TestInference {

	private static class Foo<T> {
		public Foo(Function<Void, T> func) {
			
		}
	}
	
	public static void main(String[] args) {
		
// Compiler error "Cannot infer type arguments for Foo<>"
		Foo<String> foo = new Foo<>(t -> {
			return Math.random() < 0.5 ? "first" :
				Math.random() < 0.5 ? "second" : "third";
		});
		
// Works fine
		Foo<String> foo2 = new Foo<>(t -> {
			return "string";
		});
	}
	
}
//---

Looks like quite a few possibly related bugs so this might already be fixed in a later build I guess?
Comment 1 Eclipse Genie CLA 2020-03-11 13:59:48 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. As such, we're closing this bug.

If you have further information on the current state of the bug, please add it and reopen this bug. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.