I have looked at at least 10 SO questions on get/set but cannot find mine. So I hope this is not a duplicate.  public class myint {     public int value{get;set;} }   vs   public class myint {     public int value; }   The above 2 codes look the same to me. If I want to use the myint class, I just write the code below and it can run on either class.  myint A; A.value=10;   So what is the get/set use for?
22005
I see a lot of example code for C# classes that does this:  public class Point {     public int x { get; set; }     public int y { get; set; } }   Or, in older code, the same with an explicit private backing value and without the new auto-implemented properties:  public class Point {     private int _x;     private int _y;      public int x {         get { return _x; }         set { _x = value; }     }      public int y {         get { return _y; }         set { _y = value; }     } }   My question is why. Is there any functional difference between doing the above and just making these members public fields, like below?  public class Point {     public int x;     public int y; }   To be clear, I understand the value of getters and setters when you need to do some translation of the underlying data. But in cases where you're just passing the values through, it seems needlessly verbose.
8134
The  says that public class SomeObject {   public void SomeOperation()   {     lock(this)     {       //Access instance variables     }   } }  is &quot;a problem if the instance can be accessed publicly&quot;. I'm wondering why? Is it because the lock will be held longer than necessary? Or is there some more insidious reason?
66959
I've built a few apex controllers, and like most people have copied some code from here and there. In the controllers, there's typically an expression that looks like the following:  public *var type* someName {get; set;}   Initially I thought I needed to supply a function to the get part if the VF page was grabbing data, something like so:  get = getData(); set;  public function string getData(){     return 'data!'; }   And the opposite for set (if users were inputting data). But now I see my controllers work perfectly well just having the top expression as {get;set;}.  I've looked through the salesforce docs and I've read all the parts regarding creating custom controllers - I see the get; set; being referenced, but nowhere explaining what this part does and how I can use it.  Have you come across any docs on what this part does and how I can use it?  Thank you all!  Zac
102715
Is there any difference between a volatile Object reference and AtomicReference in case I would just use get() and set()-methods from AtomicReference?
89868
In c#, is there any difference in the excecution speed for the order in which you state the condition?  if (null != variable) ... if (variable != null) ...   Since recently, I saw the first one quite often, and it caught my attention since I was used to the second one.  If there is no difference, what is the advantage of the first one?
122845
As most stories here begin, I was writing some code for a project that I was working on, and stumbled across an oddity when writing some unit tests. I was testing a method that has a Set&lt;sObject&gt; parameter, and I was attempting to pass this method a Set&lt;Account&gt;.  As Account inherits from sObject, I thought this would work fine. However, when running my test, I got the error     Method does not exist or incorrect signature: [TestClass].someMethod(Set&lt;Account&gt;)   Yes, the method that I was testing expects an argument of Set&lt;sObject&gt;, but an Account can be up-cast to an sObject, and Salesforce handles that implicitly, right?  Since Salesforce was throwing a fit when I tried to rely on implicit casting, the next thing I tried was explicitly up-casting. When I tried to explicitly up-cast my set, I was greeted with a different error     Line: someNumber, Column: otherNumber   Incompatible types since an instance of Set&lt;Account&gt; is never an instance of Set&lt;SObject&gt;   This can be reproduced with the following snippet  Set&lt;sObject&gt; testSet1; Set&lt;Account&gt; testSet2 = new Set&lt;Account&gt;();  testSet1 = (Set&lt;sObject&gt;)testSet2;   I haven't found anything in the documentation to suggest that up-casts for sets aren't allowed. Given that we can up-cast Lists and Maps, I feel this is rather unexpected.  Furthermore, knowing that an Apex set is really a Java HashSet in the back-end (look at the bottom of ), I tried to look for documentation to see if this is somehow dictated by Java, but I came up empty there as well.  I've been able to move on with my project, but this leaves me wondering...  Is there some documentation (Salesforce or Java) that explains this behavior? Failing that, can someone cobble together a feasible explanation for why Sets can't be up-cast?
56376
I'm trying to get my head around mutable vs immutable objects. Using mutable objects gets a lot of bad press (e.g. returning an array of strings from a method) but I'm having trouble understanding what the negative impacts are of this. What are the best practices around using mutable objects? Should you avoid them whenever possible?
38581
In school, I have always seen sets. I was watching a video the other day about functors, and they started talking about a set being a collection, but not vice-versa. I also heard people talking about classes. What is their relation? Some background would be nice.   It has to do with something called Russell's paradox, but I don't know what that is.   I think that the difference between a family and a set is that the former is a function and the latter is a set. Is this right?
4013
If I have two variables:  Object obj; String methodName = "getName";   Without knowing the class of obj, how can I call the method identified by methodName on it?  The method being called has no parameters, and a String return value. It's a getter for a Java bean.
1064
I know java and would normally put in getter/setter methods. I am interested in doing it in C# with the following code, but it throws a StackOverflow exception. What am I doing wrong?  Calling Code  c.firstName = "a";   Property Code    public String firstName; {     get     {         return firstName;     }     set     {         firstName = value;     } }
52524
So I was making a class the other day and used Eclipse's method to create the equals method when I realized that it generated the following working code:  class Test {   private int privateInt;   [...]   public boolean equals(Object obj) {     [...]     Test t = (Test) obj;     if ( t.privateInt == privateInt ) {     [...]   } }   t.privateInt..???? It's suppose to be private! So I guess there is one more field visibility other than private, protected, package protected and public.  So what is happening here? How is this called? Where would somebody use this? Doesn't this break encapsulation? What if the class didn't have a mutator and I changed this? Does this happen to C++ as well? Is this an OO idiom? If not, then why did Java do it?  Generally, where can I find information about this?  Thank you.
58964
I have a class with two class methods (using the classmethod() function) for getting and setting what is essentially a static variable.  I tried to use the property() function with these, but it results in an error.  I was able to reproduce the error with the following in the interpreter: class Foo(object):     _var = 5     @classmethod     def getvar(cls):         return cls._var     @classmethod     def setvar(cls, value):         cls._var = value     var = property(getvar, setvar)  I can demonstrate the class methods, but they don't work as properties: &gt;&gt;&gt; f = Foo() &gt;&gt;&gt; f.getvar() 5 &gt;&gt;&gt; f.setvar(4) &gt;&gt;&gt; f.getvar() 4 &gt;&gt;&gt; f.var Traceback (most recent call last):   File &quot;&lt;stdin&gt;&quot;, line 1, in ? TypeError: 'classmethod' object is not callable &gt;&gt;&gt; f.var=5 Traceback (most recent call last):   File &quot;&lt;stdin&gt;&quot;, line 1, in ? TypeError: 'classmethod' object is not callable  Is it possible to use the property() function with @classmethod decorated functions?
33953
Suppose I have two classes:  public class Student {     public int Id {get; set;}     public string Name {get; set;}     public IList&lt;Course&gt; Courses{ get; set;} }  public class StudentDTO {     public int Id {get; set;}     public string Name {get; set;}     public IList&lt;CourseDTO&gt; Courses{ get; set;} }   I would like to copy value from Student class to StudentDTO class:  var student = new Student(); StudentDTO studentDTO = student;   How can I do that by reflection or other solution?
414
In Java, are there clear rules on when to use each of access modifiers, namely the default (package private), public, protected and private, while making class and interface and dealing with inheritance?
25819
What is the purpose of the Using block in C#? How is it different from a local variable?
96218
I came across this code and wanted others to provide their point of view... is it good or bad ? ;)  Class ReportClass {  public string ReportName {get; set;} }   Then it was used as follows in code:  displayReport(ReportClass.ReportName = cmbReportName.SelectedValue.ToString())   That is about the simplest form example I can give you. Quetion is... why can't I find examples ? What would this be called? Is this just asking for trouble?  EDIT: I'm referring to the inplace assignment. Which I wasn't aware of until today
122201
You can use a standard dot notation or a method call in Objective-C to access a property of an object in Objective-C.  myObject.property = YES;   or  [myObject setProperty:YES];   Is there a difference in performance (in terms of accessing the property)? Is it just a matter of preference in terms of coding style?