0

I wanna code some method for hystrix default fallback methods, for example:

//declaration
public void voidDefaultFallback(generic argument list) {
    return;
}

public int intDefaultFallback(generic argument list) {
    return 0;
}

public Object nullDefaultFallback(generic argument list) {
    return null;
}
//invocation
nullDefaultFallback("a", "b");
nullDefaultFallback("a", 0);
nullDefaultFallback("a", 0, "abc");

does java support such generic method?

juzraai
  • 5,693
  • 8
  • 33
  • 47
bigpotato
  • 211
  • 2
  • 3
  • 13
  • 1
    I'm not clear understand what you exactly mean by `generic argument list`. Your examples could be described by several ways: `K, V...`, `K...` – ZhenyaM Jul 25 '18 at 09:21
  • 3
    Possible duplicate of [Java variable number or arguments for a method](https://stackoverflow.com/questions/2330942/java-variable-number-or-arguments-for-a-method) – juzraai Jul 25 '18 at 09:21
  • pass argument list object with your method – Kandy Jul 25 '18 at 09:23

3 Answers3

3

Yes, you can do that with this argument in method

public void method (Object ... objects){
        for(Object obj : objects){
            //do stuff
        }
    }

It's called varargs , you can find more info here

Leviand
  • 2,745
  • 4
  • 29
  • 43
0

You can always use

nullDefaultFallback(Object...args);
Antoniossss
  • 31,590
  • 6
  • 57
  • 99
0

For different return types with same method names you need to specify different method signatures. For example:

public void m(K...) {...}
public int m(K...) {...}

is not valid case, but, for example:

public void m(K){...}
public int m(K, K) {...}

will work fine

ZhenyaM
  • 676
  • 1
  • 5
  • 15