Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 557 Vote(s) - 3.43 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Which one to use, int or Integer

#11
One scenario to cover would be validation.

Imagine we have the following class:

class Foo{
@Min(value = 10)
int val;
}

If the user doesn't provide a value for `val` in the request, we will get a nasty `NumberFormatException`.

If `int` is replaced with `Integer`, we can use `@NotNull` and resolve this issue more gracefully.


Reply

#12
`int` is used by java for most all calculations. `Integer` is used in all forms of Collections except for primitive arrays.

Using lots of temporary Integers with thrash the garbage collector and use unprofilable CPU in the background that will cause general slowdowns in everything. Too many temporaries being trashed per second will cause the CG to enter emergency "I need memory now" mode that can cause stalls in latency critical applications (ie: real time interactive graphics, physical device controllers or communications)

So for me if I have a lot of nested calls that do no math but access a lot of collections such as using keys for maps I use Integer so as to avoid tons of auto boxing when arguments are passed.

If the operations are math intensive or used as loop counters or other math oriented operations and not stored in collections (other than primitive arrays) I use the primitive. The same goes for all the other primitives except String which is a full fledged object.
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through