REFERENCE vs VALUE TYPES - JAVA

Pubblicato il: 31 gennaio 2021
sul canale di: 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...


In questa pagina del sito puoi guardare il video online REFERENCE vs VALUE TYPES - JAVA della durata di ore minuti seconda in buona qualità , che l'utente ha caricato The Sukhdev 31 gennaio 2021, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 100 volte e gli è piaciuto 3 spettatori. Buona visione!