문제

I'm creating a UML static class diagram for AsyncTask. How should I denote doInBackground(Params... params), which has a variable number of argumetns?

도움이 되었습니까?

해결책

OK, so, first, apologies to @JBNizet for blatant code stealing (original URL to the stolen code: here).

The thing is that Java 5's varargs is just syntactic sugar for an array. Witness this code:

class Ideone
{
    public static void main (String[] args) throws java.lang.Exception
    {
        foo(args);
    }

    private static void foo(String... params) {
        System.out.println(Arrays.toString(params));
    }
}

It works. It would have worked the same if instead you had used a varargs in main() and an array in foo().

So, in UML, you can model varargs as an array.

다른 팁

AFAIK UML does not allow to do so. But if you look from the other side: varargs in Java is just an Array of objects. I believe from modeling perspective this should not make any differene.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top