1

I'm curious if there's any way to hard code a drawPolygon in Java. Usually you are supposed to do something like this

int[] x = {50,200,10};
int[] y = {20,300,50};
page.drawPolygon(x, y, 3);

and I am curious if there is any way to do something similar to this:

page.drawPolygon({50,200,10}, {20,300,50}, 3);

1 Answer 1

6

Yes, it's possible, but is not as short as you wished:

page.drawPolygon(new int[] {50,200,10}, new int[] {20,300,50}, 3);

As you already know, the short just-brackets notation for arrays is useful only for declaring attributes and local variables:

int[] x = { 50, 200, 10 };

It's a shame, a bit of syntactic sugar would have been nice/useful here. Same thing for maps, which should have a literal syntax. Dynamic languages have an advantage in this!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.