6

I know that Java uses "final" to declare a constant and that c uses "const". Just wondering what the differences are between the two.

too honest for this site
  • 12,050
  • 4
  • 30
  • 52

1 Answers1

13

In java, making something final means that it can't be reasigned to another reference to another instance, but if it's a reference to a mutable class, the mutable values inside the class can still be modified.

For example, a final String is a constant because Strings are immutable in Java, but a final ArrayList means that you cannot assign it to another ArrayList, but you can still add and remove elements to that ArrayList

DrKarl
  • 356
  • 3
  • 8