2

Just curious: I've got the following code:

@Component
public class GoogleExceptionRetryClassifier implements Classifier<Throwable, Boolean>
{
   private static final Collection<Classifier<Throwable, Boolean>> classifiers = new ArrayList<Classifier<Throwable, Boolean>>();
   static
   {
      classifiers.add((tr) -> classInCauseChain(tr, UnknownHostException.class));
      classifiers.add((tr) -> classInCauseChain(tr, SocketTimeoutException.class));

      //vv--LINE BELOW!!!!--vv
      classifiers.add(GoogleExceptionRetryClassifier::isGoogleHTTP5XXError);
   }

...

}

Is there a way on the indicated line to avoid listing the current class? The method is a static method in the same class as the static initializer block. I realize I can't do this::isGoogleHTTP5XXError because there is no instance yet, but it seems like it would be nice to have something like ::isGoogleHTTP5XXError that would infer my current class without having to spell it out. Does this exist?

xdhmoore
  • 8,935
  • 11
  • 47
  • 90
  • 5
    No. Such things were considered, but were rejected as not carrying their weight. – Brian Goetz Jul 28 '15 at 00:45
  • 1
    I would be really useful if we had some alias for the current class. Let's say uppercase `This`. This would be also help with other, non-lambda cases. This would not only shorten the code but also it would work while copying snippets between classes. – Piotr Siupa Feb 20 '19 at 14:01

0 Answers0