Im using Java 8 and have the following code:
public WeatherDTO(Map<?,?> mappedJsonData) {
if (mappedJsonData == null || mappedJsonData.isEmpty()) {
return;
}
List<?> weather = (List<?>)mappedJsonData.get("weather");
if (weather != null && !weather.isEmpty()) {
this.weather = (String) ((Map<?,?>)weather.get(0)).get("description");
}
Map<?,?> jsonMain = (Map<?,?>)mappedJsonData.get("main");
if (jsonMain != null && !jsonMain.isEmpty()) {
this.temperature = (double)jsonMain.get("temp") - 273.0;
this.humidity = (int)jsonMain.get("humidity");
}
}
This code works fine when im running the web app within Eclipse and embedded Tomcat. There is also no Problem shown in Eclipse Problems view.
But when im starting a maven compile from my shell/bash im getting the following error:
[ERROR] COMPILATION ERROR : [INFO] -------------------------------------------------------------
[ERROR] /home/xxx/xxx/xxx/src/main/java/xxx/xxx/xxx/weather/WeatherDTO.java:[52,64] incompatible types: capture#1 of ? cannot be converted to double
[ERROR] /home/xxx/xxx/xxx/src/main/java/xxx/xxx/xxx/weather/WeatherDTO.java:[53,58] incompatible types: capture#2 of ? cannot be converted to int
Does anybody have a idea what im doing wrong? The maven compiler plugin seems to be up to date and my JAVA_HOME points to a Java 8 version.
Snippet from the pom.xml
<plugin>
<inherited>true</inherited>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<encoding>${project.build.sourceEncoding}</encoding>
<showWarnings>false</showWarnings>
<showDeprecation>false</showDeprecation>
</configuration>
</plugin>
Configuration of java.version is 1.8; Maven is 3.0.4.
I get the same error as you. But the following code fixes it. I've made the code a method instead of a constructor, but I think you can ignore that, eh?
private String weather;
private double temperature;
private int humidity;
public void WeatherDTO(Map<?, ?> mappedJsonData) {
if (mappedJsonData == null || mappedJsonData.isEmpty()) {
return;
}
List<?> weather = (List<?>) mappedJsonData.get("weather");
if (weather != null && !weather.isEmpty()) {
this.weather = (String) ((Map<?, ?>) weather.get(0)).get("description");
}
Map<?, ?> jsonMain = (Map<?, ?>) mappedJsonData.get("main");
if (jsonMain != null && !jsonMain.isEmpty()) {
this.temperature = (Double) jsonMain.get("temp") - 273.0;
this.humidity = (Integer) jsonMain.get("humidity");
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With