Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Guice - have the same erasure - compilation error after java upgrade from v6 to v7

I am upgrading java version from 6 to 7 for my project. It used to compile fine with java 6.

@Provides
VptchProvIntf provideVptchProv(NeVersion neVersion, Provider<ClVptchProv> classicProvider,      Provider<RsVptchProv> rsProvider)
{
    return (VptchProvIntf)provideForPlatform(neVersion, classicProvider, rsProvider);
}

@Provides
StsnVcnProvIntf provideVptchProv(NeVersion neVersion, Provider<ClStsnVcnProv> classicProvider, Provider<RsStsnVcnProv> rsProvider)
{
    return (StsnVcnProvIntf)provideForPlatform(neVersion, classicProvider, rsProvider);
}

This is snapshot from a de-compiled class. Types were not erased by compiler and code compiles fine.

But after java upgrade to version 7, this code has started giving compilation error

error: name clash: provideVptchProv(NeVersion,Provider,Provider) and provideVptchProv(NeVersion,Provider,Provider) have the same erasure

Has Java 7 changed anything that is not allowing Guice to work.

Note : Google Guice version is 2.0

Do I need to update Guice or is there any workaround?

like image 357
codingenious Avatar asked Sep 24 '14 10:09

codingenious


1 Answers

The Java 5 and 6 compilers had a bug that would accept your methods, because they considered the signature to include the return type in the check.

In Java 7, methods cannot have the same erased signatures, regardless of their return types. See this blog post and this bug report.

In your case, the answer is to rename one of your methods.

like image 161
Tavian Barnes Avatar answered Sep 21 '22 04:09

Tavian Barnes