REFERENCE vs VALUE TYPES - JAVA

Publié le: 31 janvier 2021
sur la chaîne: The Sukhdev
100
3

*** CORRECTION: on 1:20 of the video, it incorrectly states that String foo = "foo" is equivalent to:
String foo = new String("foo")
... this is not really true. In fact, it's also misleading to say that Strings are stored in the heap - they are actually stored in a specific place in the heap: "The String Pool". The 'new' keyword will create an object in the heap that references the string in the pool (or create one if it doesn't already exist). Creating a string without using the 'new' keyword will NOT create an additional string object in the heap; it will simply point to the string in the string pool or add it to the pool if it doesn't already exist. This is why "foo" == "foo" will be true (both point to the same string in the pool) and new String("foo") == "foo" will be false (the left part of the expression references an object in the heap, which then references the string in the pool BUT '==' checks for reference, NOT for value). ***

NOTE: a stack is a linear data structure with a particular order in which the operations are performed: first-in, last-out. Also, elements in the stack are encapsulated in frames. To learn more about the role of frames in the stack : https://stackoverflow.com/questions/1...


Sur cette page du site, vous pouvez voir la vidéo en ligne REFERENCE vs VALUE TYPES - JAVA durée heure minute seconde en bonne qualité , qui a été Téléchargé par l'utilisateur The Sukhdev 31 janvier 2021, Partagez le lien avec vos amis et connaissances, sur youtube cette vidéo a déjà été regardée 100 fois et il a aimé 3 téléspectateurs. Bon visionnage!