Support `Self` type with extension methods
See original GitHub issueIs There any way that we could write extension methods for generic types? For example:
public static <T> T println(@This T thiz) {
System.out.println(thiz);
return thiz;
}
Or
public static <T extends Collection<? extends Long>> T printMax(@This T thiz) {
System.out.println(thiz.max(Long::compareTo));
return thiz;
}
Thanks again for this awesome library.
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
How to implement and call a custom extension method - C# ...
In this article ... This topic shows how to implement your own extension methods for any .NET type. Client code can use your...
Read more >c# - How to create extension methods for Types - Stack Overflow
The short answer is it cannot be done; extension methods need to work on an instance of something.
Read more >Extension methods - Dart
The members of the extension can be methods, getters, setters, operators. Extensions can also have static fields and static helper methods. Implementing generic ......
Read more >Creative Use of Extension Methods - Oleksii Holub
This is extremely convenient in cases where you want to add functionality to types you don't have control over. In fact, I think...
Read more >The sad state of extension methods in the JVM ecosystem
The toTitleCase extension method is defined as a static method · It works with nulls · We can reuse existing utility methods like...
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
Fixed with af9746b
Watch the Self Type documentation for details
UPDATAE:
With release 0.47-alpha
@Self
has been rewritten to fully support the Self type. Use it in method return types, parameter types, and field types. Learn more.