1

I'm writing a code in Kotlin language (of JetBrains) using IntelliJ and i'm facing a error on compiler where the compiler cannot find the correct parameter type of a function, always saying that the function receve a Nothing parameter.

Someone have any idea of what is the problem?

Print Screen showing the error on IntelliJ IDE

In the image, the console show the compiler error, but a help on center of the screen shows that IntelliJ can find the correct parameter type of the function, but compiler not.

==== Edited ==========================================

The Java code is:

  @Transactional
  public int deletar(BuscaInfo info) {

    // ----  Criando a busca ao banco:
    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaDelete query = cb.createCriteriaDelete( info.classe );
    Root root = query.from( info.classe );

    // Cláusula WHERE do banco:
    Predicate[] preds = WhereBuilder.build(cb, root, info.where);
    if (preds.length < 1) {
      throw new MsgException(JsonResponse.ERROR_EXCECAO,null,"Os parâmetros de filtragem da QueryString não são válidos.");
    }
    query.where(preds);


    // A busca ao banco:
    int qtd = em.createQuery(query).executeUpdate();
    return qtd;
  }

and info.classe is of type Class<?>.

Using Hibernate 5.x and JPA 2.1 api to compile.
That code works on WildFly 9.x and 10.x.

1 Answer 1

2

Can you please check the type of q variable? (navigate to it, the run alt+q) I suppose its type is CriteriaDelete<*>, and none of these from methods can be called for the same reasons they can't in Java on a variable of type CriteriaDelete<?>: we can't say exactly what T was there when the instance was created.

But diagnostic, of course, could be better here. I've created issue on this

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks for reply. Yes, the q variable is CriteriaDelete, but this code is a rewrite of a Java code i have, and in Java i call this .from( Class<?> ) method of CriteriaDelete and CriteriaUpdate (not post about, but i have same issue with CriteriaUpdate). If i not call this method, an exeception is thrown saying that root need to be specified. Thanks to open an issue =D
It's very strange, that it works in Java. Can you please share the relevant Java version?
Edited the question adding the piece of code write on Java.Thanks for your help.
There is a tricky moment in your Java code: you use raw type CriteriaDelete query that effectively turns off exact type matching when calling from on it. If you use CriteriaDelete<?> type instead you will get a similar error. In Kotlin there are no raw types, but you always can use unsafe cast like (q as CriteriaDelete<Any>).from(info.classe as Class<Any>) that would be a fair Kotlin version of your Java code

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.