Interface Overload Generic Member - Compiler error when removing overload
See original GitHub issueBug Report
Removing an overload member Controller.handle
from Controller
causes a compilation error.
🔎 Search Terms
- Interface overload
- Member Type Parameter
- Works When Removing overload
⏯ Playground Link
💻 Code
Code below compiles
export interface Controller {
handle<T>(httpRequest: HttpRequest<T>): HttpResponse<T>;
handle<TRequest, TResponse>(httpRequest: HttpRequest<TRequest>): HttpResponse<TResponse>;
}
Code below does not compile
export interface Controller {
// handle<T>(httpRequest: HttpRequest<T>): HttpResponse<T>;
handle<TRequest, TResponse>(httpRequest: HttpRequest<TRequest>): HttpResponse<TResponse>;
}
Code below does not compile
export interface Controller {
handle<T>(httpRequest: HttpRequest<T>): HttpResponse<T>;
// handle<TRequest, TResponse>(httpRequest: HttpRequest<TRequest>): HttpResponse<TResponse>;
}
🙁 Actual behavior
Code does not compile when removing any of the overloads.
🙂 Expected behavior
Since having an overload in Controller.handle
works, having just one member with the correct signature should also work.
Additional Info
Issue Analytics
- State:
- Created a year ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
Java Generic Interface method-overload - Stack Overflow
But now I'm getting a compiler error i dont understand: java:15: error: name clash: insert(T,int) and insert(C, ...
Read more >Overload resolution failed because no accessible ...
A call to an overloaded generic procedure cannot be resolved because the compiler cannot access any overloaded version with the appropriate ...
Read more >Overloading and generic constraints - Jon Skeet's coding blog
So, the first method is rejected, the second is fine, so it compiles with no problems. The important thing to note is that...
Read more >Chapter 8. Classes - Oracle Help Center
Like methods, they may be overloaded (§8.8.8). ... It is a compile-time error if an inner class declares a member that is explicitly...
Read more >Overload resolution - Kotlin language specification
Non-extension member callables named f of type AN . If at least two of these sets are non-empty, this is a compile-time error....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Your interface says: This interface provides this generic method.
Your class implements no such generic method.
Simplified, you try this:
The interface allows me to call
handle
with arbitrary generic arguments. The class ignores this, and just returns astring
. So when calling the method I end up with nonsense:When adding an overload to this example it will compile just fine as well, like your example. Playground link
I don’t recall offhand what the assignability rules are around overload targets. I would have said “assignable to each” but that’s clearly not what’s going on.