viernes, 1 de noviembre de 2019

20. Vaadin 14. Packaging, deploying, war (1). Compilation problems

0. Introduction

To deploy an application it is important to test this check-list:


  1. There are no compilation errors in Eclipse
  2.  The application runs
  3.  The Maven pom.xml file has no errors
  4.  There are no problems generating the "war" file


1. Compilation errors

I have made some java code that behaves in an odd mode. I have no compiler errors in Eclipse, but when I want to make execute Maven with the goals "clean package" and profile "production", I get compilation errors from Maven. Here are the errors:

1.1 Incompatible types: int cannot be converted to java.lang.Short

This error is produced in this scenario:

1. A function is declared as:
    String MyFunction (Short counter) {..}

2. A call to this function:
    String myString=MyFunction(1);  // No compile errors in Eclipse

The solution consists of changing the parameter as follows.
  String myString=MyFunction(Short.valueOf("1"));


1.2 Incompatible types: cannot infer type-variable(s) T,U,T,Q
[ERROR]     (argument mismatch; java.util.Comparator<T> cannot be converted to java.util.Comparator<? super U>)

This error is produced in this scenario:

1. A variable is declared as:
    Comparator<Base> myComp;

2. Afunction is declared as:
    public static <Q>  Q getMtd(Base bean, String fldName) {..}

2. A call to this function:
    myComp=Comparator.comparing(
     a -> getMtd(a, nm), 
     Comparator.reverseOrder());  // No compile errors in Eclipse

The solution consists of this strange typing
  myComp=Comparator.comparing(
     a -> getMtd(a, nm), 
     Comparator.<Base>reverseOrder()); 



No hay comentarios:

Publicar un comentario