Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android Build a Simple Android App with Java Basic Android Programming Generating a Random Number

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 91,253 Points

What's the (n: 3) in the nextInt() parameter?

Can I ask, what the n: refers to in the nextInt() method?

I understand were just passing an integer parameter to give the range of numbers to be returned but my Android studio doesn't come up with this when I pass it in.

Thanks! :)

1 Answer

andren
andren
28,558 Points

It is a parameter name hint, if you look at the documentation for the nextInt method you can see that n is the parameter name used by that method.

It is a feature found in most IntelliJ based IDEs. Whether it is enabled by default or not seems to change from version to version. If you want to enable it you can open the settings window then go to Editor -> General -> Appearance and check "Show parameter name hints".

The IDE tries to hide the hint if the parameter is likely to be obvious, so by default it won't show up on all method calls even with that option enabled, but that behavior can be configured.

I'm using the auto populated option nextInt() provided by android studio but when I drop a 3 into the parenthesis throws a bound into the parenthesis. ( bound 3); vs randomGenerator.nextInt( n 3) which is what the instructors line looks like.

Is this a problem? I am running a newer version of android studio

andren
andren
28,558 Points

No that's completely fine. The parameter name was changed from n to bound in Java 8. You can see that on this documentation page. It was likely changed since n is a pretty random and nondescript name.

So if you are using Java 8 or later then that is the expected result.