Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » incorrect Type Inference(JDT Compiler cannot resolve the type the JDK Compiler can be resolved.)
incorrect Type Inference [message #1527209] Thu, 25 December 2014 02:12 Go to next message
taichi SATO is currently offline taichi SATOFriend
Messages: 2
Registered: December 2014
Junior Member
Hi

i wrote code below.

import java.util.Optional;
import java.util.function.Function;

public class Main {
  public static void main(String[] args) {
    Optional.of("aaa")
        .map(s -> new F<>(s)) // (1) no problem
        .map(t ->             // (2) <U> is Object. this is incorrect. JDK resolve <U> is Integer.
            t.map(f -> 200))  // (3) <Z> is Integer. no problem.
        .map(n -> n + 300)    // (4) n is Object. but should be Integer.
        .ifPresent(System.out::println);
  }

  static class F<T> {
    T value;

    F(T value) {
      this.value = value;
    }

    public <Z> Z map(Function<? super T, ? extends Z> fn) {
      return fn.apply(this.value);
    }
  }
}



this code can be compiled by JDK(1.8.0_25) compiler.
but JDT(4.4.1) compiler cannot be compiled.
i use plugins below.

org.eclipse.jdt 3.10.0.v20140925-0400
org.eclipse.jdt.core 3.10.0.v20140902-0626


i think that this behavior is JDT bug. but now i confused.
Any suggestions?

  • Attachment: Main.java
    (Size: 0.68KB, Downloaded 124 times)
Re: incorrect Type Inference [message #1530163 is a reply to message #1527209] Fri, 26 December 2014 18:49 Go to previous messageGo to next message
Stephan Herrmann is currently offline Stephan HerrmannFriend
Messages: 1853
Registered: July 2009
Senior Member
I can reproduce the problem with JDT 4.4.1 and up-to 4.5 M2. It has been fixed in 4.5 M3 (probably via https://bugs.eclipse.org/437444 which in turn adopts a few changes from JLS post Java 8 release).

cheers,
Stephan
Re: incorrect Type Inference [message #1542845 is a reply to message #1530163] Fri, 02 January 2015 22:26 Go to previous message
taichi SATO is currently offline taichi SATOFriend
Messages: 2
Registered: December 2014
Junior Member
thanks for your information.
Previous Topic:importing Mallet in Eclipse Helios
Next Topic:Luna - Run Configurations: "Eclipse Application" not found
Goto Forum:
  


Current Time: Sat Jul 27 01:21:02 GMT 2024

Powered by FUDForum. Page generated in 0.02399 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top