Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8354680

Modifying static field via an instance should only affect that instance, not all

XMLWordPrintable

    • generic
    • generic

      A DESCRIPTION OF THE PROBLEM :
      Static fields can be accessed and modified through both the class name and an instance. However, modifying a static field via an instance affects all instances of the class, which feels unfair because it changes the shared state for every object, even though each instance is supposed to be distinct.

      If we access a static field through an instance, it would make more sense if modifying it only affected that specific instance. This would help keep each instance independent while still allowing access to static variables through an instance.

      Another option would be if static fields could only be modified using the class name, not through instances. This would help avoid confusion and ensure that developers don't accidentally treat static fields like instance-specific data.



       

            Unassigned Unassigned
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: