Latest Questions tagged Reference

Browse all latest questions tagged Reference

95
Votes
Published 06 Sep, 2022
Java - How to create a variable that can be set only once but isn't final in Java

I want a class that I can create instances of with one variable unset (the id), then initialise this variable later, and have it immutable after initialisation. Effectively, I'd like a final variable...

23
Votes
Published 13 Jul, 2022
Jquery - Get instance / reference from jQuery prototype function ($.fn)

I wrote a jQuery plugin that uses a prototype. Example: function MyWidgetConstructor(element) { this.id = 'test'; this.$element = $(element); this.$element.data('instance', this);...

70
Votes
Published 10 Aug, 2022
Jquery - Obtain a reference to <script> parent element

I have a similar problem like posted here but instead of obtain the parent id, how Can I get a reference to the script parent without having to code an id for the script tag? For example, I have the...

60
Votes
Published 09 Aug, 2022
Jquery - jQuery & Ajax: ReferenceError: ajax is not defined

I get a ReferenceError: ajax is not defined error in browser console when I try to make an ajax call. I'm pretty sure I properly loaded the jQuery library, therefore I don't understand how can...

49
Votes
Published 07 Aug, 2022
Python - How to reference a dict object?

I have a Python dict object d. d = {'a': 1, 'b': 2, 'c': 3}. My problem is really simple. I want to reference a variable to the elements of d. For example, something like: In[1]: p = d['a'] &gt;&gt;&...

29
Votes
Published 25 Aug, 2022
Java - Nested Objects Best Practice

What is the best practice for referencing nested objects? Say I have the following: class Outer { private InnerA innerA; //getters and setters } class InnerA { private InnerB innerB; //getter...

40
Votes
Published 10 Aug, 2022
Java - Duplicating objects in Java

I learned that when you modify a variable in Java it doesn't change the variable it was based on int a = new Integer(5); int b = a; b = b + b; System.out.println(a); // 5 as expected System.out.print...

78
Votes
Published 06 Sep, 2022
Java - Can I change objects in one ArrayList using references in another one?

First array list:- ArrayList&lt;Object&gt; list1; Second array list:- ArrayList&lt;Object&gt; list2; Suppose I have filled list1 with some objects. Now I copy some of objects from list1 using list2.ad...

40
Votes
Published 03 Sep, 2022
Java - Have you ever used PhantomReference in any project?

The only thing I know about PhantomReference is, If you use its get() method, it will always return null and not the object. What's the use of it? By using PhantomReference, you make it sure that t...

837
Votes
Published 26 Apr, 2022
Python - How do I pass a variable by reference?

Are parameters are passed by reference or value? How do I pass by reference so that the code below outputs 'Changed' instead of 'Original'? class PassByReference: def __init__(self): self....

86
Votes
Published 01 Sep, 2022
Java - Recursive Insert for Binary Tree

I'm working on code for insertion into a binary search tree. It works for the first node I insert, making it the root, but after that it doesn't seem to insert any nodes. I'm sure it's a problem with...

23
Votes
Published 16 Apr, 2022
Javascript - Javascript create reference to an object property?

I understand that in javascript, primitives are passed by value and objects are passed by reference. I'm interested in creating a workaround of some kind that would let me get a reference to an objec...

152
Votes
Published 26 Aug, 2022
Java - What are classes, references, and objects?

I've been programming Java for 2 years now, and I have encountered a problem where I couldn't understand and differentiate class, reference, and an object. I am not sure if a class or reference are th...

104
Votes
Published 26 Apr, 2022
Python - Is there a difference between "==" and "is"?

My Google-fu has failed me. In Python, are the following two tests for equality equivalent? n = 5 # Test one. if n == 5: print 'Yay!' # Test two. if n is 5: print 'Yay!' Does this hold tr...

107
Votes
Published 25 Aug, 2022
Java - Increment an Integer within a HashMap

Do I have to return the object and then put a new one in ? Or can I just directly increment ? Integer temp = myMap.get(key); temp++; myMap.put(key, temp); there is no way to just do this (this does...