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

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 83,943 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,390 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,390 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.