Eclipse muestra argumentos de tipo genérico de inferencia: desea eliminar esta advertencia sin suprimirla

I am trying to get all log from svn repository using SVNKit. It is working fine, but saw an infer generic type argument warning message. I have tried to cast the line

repository.log(new String[]{""}, null, START_REVISION, HEAD_REVISION, true, true);

Collection<SVNLogEntry>

But warning is still there . Is it possible to remove this warning without suppressing it ?

    private Collection<SVNLogEntry> getAllSvnLogsFromStart_Revision()   {
    DAVRepositoryFactory.setup();
    SVNRepository repository = null;
    Collection<SVNLogEntry> logEntries = null;
    try {
        repository = SVNRepositoryFactory.create( SVNURL.parseURIEncoded( SVN_URL ) );
        ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager(userName, passWord);
        repository.setAuthenticationManager(authManager);          
        logEntries = repository.log(new String[]{""}, null, START_REVISION, HEAD_REVISION, true, true);
    }catch (SVNException e) {
        e.printStackTrace();
    }
    return logEntries;
}

mensaje de advertencia


svnkit api

preguntado el 12 de junio de 14 a las 11:06

2 Respuestas

Como SVNRepository.log() devuelve un crudo Collection type you will have to deal with unchecked conversion. The cleanest way would be to minimize @SuppressWarnings field of effect by applying it to the variable declaration:

@SuppressWarnings("unchecked")
Collection<SVNLogEntry> logEntries = repository.log(new String[]{""}, null, START_REVISION, HEAD_REVISION, true, true);
return logEntries;

Respondido el 13 de junio de 14 a las 11:06

hi @pingw33n got your point, still my question is, are there any way to remove this warning without using suppresswarning? - anirbano

The unchecked warning cannot be worked around with a direct conversion because Java can't statically define the type safety of the operation, as the content of the array is not know; the solution would be to make the content of the array known to java:

    Collection<SVNLogEntry> typesafe = new ArrayList<SVNLogEntry>();

    for (Object o : repository.log(new String[]{""}, null, START_REVISION, HEAD_REVISION, true, true)) {
        typesafe.add((SVNLogEntry)o);
    }

this comes with a performance penalty but allows the runtime to be sure of what the typed array content is and makes the warning disappear.

However, if you are looking for an alternative to suppress the warning without using SuppressWarning, there is this other route (which applies to the project as a whole, sadly):

To disable the warning without suppress warning, you have go to preferences, under java > compiler > error/warnings, where there is a Generic types fold containing these messages

warning configuration

putting them to ignore should also remove the tooltip.

Respondido el 13 de junio de 14 a las 14:06

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.