@EDIT: I want the function to be able to search without me saying what are the variables that it should be searching. For example, I want the same function to search for minimumClients + Location and give me all that contain those values, but if the user only chose pricePerNight + roomsQuantity then it should search on the same list for different variables without me telling it which variables to search.  I do not want to add inside the function ".getLocation().equals(location)", I want to make it so it compares the values passed as an argument that are != from NULL to the objects inside the list.  List&lt;Property&gt; properties = new ArrayList&lt;&gt;(); // Let's say I want to look for properties with the minimumClients = 4; // I would do Property p = new Property(); p.setMinimumClients(4); properties = getPropertyList(p); // That would give me the Property 3  // But if I want to look for properties with pricePerNight = 30 and location = "Portugal" I would: Property p = new Property(); p.setPricePerNight(20); p.setLocation("Portugal); properties = getPropertyList(p); // This would give me the Property 1 using the same function above. I do not want to specify what I am looking for, I want to make it so it knows what I am looking for.   This is what I mean:  I have the following class  public class Property() {     private int minimumClients;     private int maximumClients;     private float pricePerNight;     private String location;     private int roomsQuantity; }   I'll be needing to search for properties, meaning I can either search:   For a location For a price per night For a location and number of rooms For a location, with given number of rooms and a given price For a location and a minimum number of clients   etc.  I'll be having a list of properties in another class called Repository  public class Repository() {     private List&lt;Property&gt; properties; }   What I want to know is: Due to the huge amount of searching possibilities on a property, is there any way I can send an object containing only the information I want to search for, and while iterating through the properties list only return the properties that contain all the object information?  Example:  public class Repository() {     private List&lt;Property&gt; properties; // Assume a constructor exists      // I'll be using a foreach here     // property contains location = "Spain" and roomQuantity = 2     // The rest is null, I want to add to the list properties that are located in spain and contain 2 rooms     public List getPropertiesList(Property property) {         List&lt;Property&gt; newList = new ArrayList&lt;&gt;();          for(Property p : this.properties)         {             // Is there any function I can use here to check if it contains the info I'm searching for, not caring if others are different?             if(p.containsEqualInfo(property))             {                 newList.add(p);             }         }          return newList;     } }   Basically:  I want to search (for example) and return a list of all the properties that are located in Spain and have a number of rooms equal to 2, not caring about the other variables values.  Property1 0 3 30 Portugal 2  Property2 0 3 30 Spain 2  Property3 4 7 120 Spain 2  Property4 0 10 300 Spain 3   If I had the above list inside the repository, once I called the function (getPropertiesList(p), p = the object that only contains spain and 2) the returned list would contain:  Property2 + Property3
13087
I want to filter a java.util.Collection based on a predicate.
48814
I am trying to save data to a database on a button push, but the variables seem to be private by the nature of where they are defined. I have tried to move where they are defined, but this seems to produce other errors.  Given a fix, why was it fixed that way?  The code follows.  namespace enable {     public partial class Form1 : Form     {         public Form1()         {             InitializeComponent();             OleDbConnection favouriteConnection = new System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\\\\192.168.123.5\\Share\\Matt\\BugTypes.mdb");             string strSQL = "SELECT CategoryName, Show " + "FROM [Categories] WHERE Show = 'Yes' " + "ORDER BY CategoryName";             OleDbDataAdapter adapter = new OleDbDataAdapter(strSQL, favouriteConnection);             OleDbCommandBuilder cBuilder = new OleDbCommandBuilder(adapter);             DataTable dTable = new DataTable();             adapter.Fill(dTable);             BindingSource bSource = new BindingSource();             bSource.DataSource = dTable;             dataGridView1.DataSource = bSource;             adapter.Update(dTable);         }         private void button1_Click(object sender, EventArgs e)         {             adapter.Update(dTable);//this is the button that needs to do the save, but can't see the variables.         }     } }
49686
Sometimes when I am debugging code in Eclipse it happens that although I can see and inspect class member variables without any difficulty I am unable to inspect the values of variables declared locally within functions. As an aside, any parameters to the current function lose their 'real' names and instead one sees their values listed in the Variables window as arg0, arg1, arg2, etc but at least the values are visible.  This is occurring at present in relation to classes defined within the core JDK. I have verified that the installed and current JRE is a JDK.  Is anybody able to shed some light on this behaviour?
71027
The following code fails to compile stating  "A local variable named 'st' cannot be declared in this scope because it would give a different meaning to 'st', which is already used in a 'child' scope to denote something else":           var l = new List&lt;string&gt;();         l.Find(st =&gt; st.EndsWith("12"));         string st = "why this fails?";   I understand why this won't work:          string preParent = "";         {             string preParent = "Should fail cause we change the meaning";         }   When we do the following we get "CS0103: The name 'postParent' does not exist in the current context":          {             string postParent=string.Empty;         }         postParent = "Should this work?";   What I don't get is why is the compiler smart enough to see that postParent is not within scope, but won't let me define a new variable that has the same name as a variable used within a child scope (which is obviously out of scope at this point).   Is the compiler simple enforcing scope by refusing to let me use the variable? If so this makes sense.  ===========  Edited:   I guess what I also find interesting is how you can have the same variable within two child scopes in a single method, so this is valid:          {             string thisWorks= string.Empty;         }         {             string thisWorks= "Should this work?";         }   I'm just a little curious that you can have two variables with the same name as long as they are at the same level (if you look at scope as a tree). This makes sense because you can have local variables in two methods of the same class with the same name.   I'm just surprised that the compiler is able to differentiate and allow this, while it wouldn't allow the postParent variable. And is this a technical limitation or was this a design decision? That's what I'm really trying to get at;-)
46378
Can someone explained, as detailed as possible, the differences between the following types?  List List&lt;Object&gt; List&lt;?&gt;   Let me make this more specific. When would I want to use  // 1  public void CanYouGiveMeAnAnswer(List l) { }  // 2 public void CanYouGiveMeAnAnswer(List&lt;Object&gt; l) { }  // 3 public void CanYouGiveMeAnAnswer(List&lt;?&gt; l) { }
51358
How do you decide between passing arguments to a method versus simply declaring them as object instance variables that are visible to all of the object's methods? I prefer keeping instance variables in a list at the end of the Class, but this list gets longer as my program grows. I figure if a variable is passed often enough it should just be visible to all methods that need it, but then I wonder, &quot;if everything is public there will be no need for passing anything at all!&quot;
103
I am playing with LINQ to learn about it, but I can't figure out how to use Distinct when I do not have a simple list (a simple list of integers is pretty easy to do, this is not the question). What I if want to use  on a list of an Object on one or more properties of the object?  Example: If an object is Person, with Property Id. How can I get all Person and use Distinct on them with the property Id of the object?  Person1: Id=1, Name="Test1" Person2: Id=1, Name="Test1" Person3: Id=2, Name="Test2"   How can I get just Person1 and Person3? Is that possible?  If it's not possible with LINQ, what would be the best way to have a list of Person depending on some of its properties in .NET 3.5?
77567
I've read in the  and the  the mention of inner classes. What is their purpose?  I see in the Apex Workbook that they used private variables and setter/getter methods in the inner class, but why didn't they just do that in the outer class with a constructer, getter, and setter?
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.
115823
Many times when I am watching others code I just want to find where and how a variable is defined. Normally what I do now is look for the type of the variable until I find the definition, that is very time consuming. And I guess that there are some tools that can help me in this rutinary situation. Any suggestion in some tools or commands to help me in this task?.  I know that using a GUI and creating a project this is done automatically I am talking of a way to do this without a GUI. I am working with only text mode. I am running under Linux and I am using C/C++, but suggestions for other languages are welcome.  Thanks a lot.  A possible solution  Michel in one of his comments propose a simple an effective solution define again the variable, in that case in compilation time, the compiler will inform where is the previous definiton. Of course to apply this solution we need to think previously in the locality of the variable.
98204
During my work with databases I noticed that I write query strings and in this strings I have to put several restrictions in the where-clause from a list/array/collection. Should look like this:  select * from customer  where customer.id in (34, 26, ..., 2);   You can simplify this by reducing this to the question that you have collection of strings and want to create a comma-separated list of this strings in just one string.  My approach I have used so far is something like that:  String result = ""; boolean first = true; for(String string : collectionOfStrings) {     if(first) {         result+=string;         first=false;     } else {         result+=","+string;     } }   But this is as you can see very ugly. You cannot see what happens there on the first look, especially when the constructed strings (like every SQL query) is getting complicated.  What is your (more) elegant way?
107627
Is it the same convention as those used in known programming languages such as Java and C? I'm trying to create a lot of variables and I want it to start with a number, but I'm not sure if it's okay.
13663
Assume you have some objects which have several fields they can be compared by:  public class Person {      private String firstName;     private String lastName;     private String age;      /* Constructors */      /* Methods */  }   So in this example, when you ask if:  a.compareTo(b) &gt; 0   you might be asking if a's last name comes before b's, or if a is older than b, etc...  What is the cleanest way to enable multiple comparison between these kinds of objects without adding unnecessary clutter or overhead?   java.lang.Comparable interface allows comparison by one field only Adding numerous compare methods (i.e. compareByFirstName(), compareByAge(), etc...) is cluttered in my opinion.   So what is the best way to go about this?
17511
So this seems pretty basic but I can't get it to work.  I have an Object, and I am using reflection to get to it's public properties.  One of these properties is static and I'm having no luck getting to it.  Public Function GetProp(ByRef obj As Object, ByVal propName as String) as PropertyInfo     Return obj.GetType.GetProperty(propName)  End Function   The above code works fine for Public Instance properties, which up until now is all that I have needed.  Supposedly I can use BindingFlags to request other types of properties (private, static), but I can't seem to find the right combination.  Public Function GetProp(ByRef obj As Object, ByVal propName as String) as PropertyInfo     Return obj.GetType.GetProperty(propName, Reflection.BindingFlags.Static Or Reflection.BindingFlags.Instance Or Reflection.BindingFlags.Public)  End Function   But still, requesting any Static members return nothing.  .NET reflector can see the static properties just fine, so clearly I am missing something here.
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.
81854
When I define an object of a class using new like this  $blah = new Whatever();   I get autocomplete for $blah. But how do I do it when I have $blah as a function parameter? Without autocomplete I am incomplete.  Edit: How do I do it if it's in an include and PDT or Netbeans can't figure it out? Is there any way to declare types for variables in PHP?
112004
I have a Linq query that I want to call from multiple places:  var myData = from a in db.MyTable              where a.MyValue == "A"              select new  {                             a.Key,                             a.MyValue                           };   How can I create a method, put this code in it, and then call it?  public  ???  GetSomeData() {    // my Linq query }