question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support `Self` type with extension methods

See original GitHub issue

Is 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:closed
  • Created 5 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
rsmckinneycommented, Nov 22, 2018

Fixed with af9746b

Watch the Self Type documentation for details

0reactions
rsmckinneycommented, Mar 10, 2019

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found