Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read SiteMap

Tags: , , , ,

Sponsored Links



Make a static reference to the non-static field

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 02-03-2010
Member
 
Join Date: Dec 2009
Posts: 213
Make a static reference to the non-static field

Hello,
I used the log, the variable is not static what is normal
Code:
private Log l = LogFactory.getLog (TreeNodeMaintenance.class);
I created a method that is static and I used this method in Log. What i am trying is to make a static reference to a non-static field. How can I do this in java, which method or what logic I have to use. Thanks in advance.

Last edited by Aaliya Seth : 02-03-2010 at 11:13 AM.
Reply With Quote
  #2  
Old 02-03-2010
Member
 
Join Date: Nov 2009
Posts: 335
Re: Make a static reference to the non-static field

Hello,
In this case, you must also declare your static variable log, just have a look a the following syntax in your case
Code:
private static Log l = LogFactory.getLog (TreeNodeMaintenance.class);
I hope you are understanding what I have tried to explain you here. If you have any more queries regarding this then you can post back and also remember to post with the error you get.

Last edited by NetWorkInG : 02-03-2010 at 11:15 AM.
Reply With Quote
  #3  
Old 02-03-2010
Member
 
Join Date: Dec 2009
Posts: 211
Re: Make a static reference to the non-static field

Hello,
I think even I have a similar kind of a problem with this. My problem is that the project contain many small projects in it and each project uses a lot of class and all the sales person Log class. So if I change the variable is static log log I changed one of Development standards specified by the specifications of development. Any help on this is highly appreciated. Thanks in advance.
Reply With Quote
  #4  
Old 02-03-2010
Member
 
Join Date: Nov 2009
Posts: 447
Re: Make a static reference to the non-static field

Hello,
You have a design problem, you have a static method so common to all classes that you will call by a "myclass.method()" in which you want to access an instance variable (not static so) This is not possible and the compiler you say very well. Having used rarely logs (curiosity), I can not let you about this to use or not. Otherwise, rather than declaring log into class attribute, you can not create / recover within your static method? Finally, your method requires that it really be static.
Reply With Quote
  #5  
Old 02-03-2010
Member
 
Join Date: Dec 2009
Posts: 213
Re: Make a static reference to the non-static field

Hello,
I have one more query, what concerns the method must be static but I'll try to declare the log variable in static method. I think it is a solution and I'll do with the project manager very soon and if it is possible to make this change, it would be great. Till then if you have any other alternative for this the please reply back with it and if it fits my needs then I will use it.
Reply With Quote
  #6  
Old 02-03-2010
Member
 
Join Date: Nov 2009
Posts: 520
Re: Make a static reference to the non-static field

Hello,
This is the general syntax of how you can do this, just and example or is a sample code and not the real code, below shown in just a syntax of what you will actually have in your code
Code:
public  class MyClass
{
  public static void mystamet(MyClass o)
   {
    o.mynstamet();
  }
 
  public void mynstamet()
  {
  }
}

public class MyClass
{
 public static void myMethod()
   {
   f();
  }

   public static void f()
  {
   }
}
Reply With Quote
Reply

  TechArena Community > Software > Software Development


Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Make a static reference to the non-static field"
Thread Thread Starter Forum Replies Last Post
Java - static field problem Miles Runner Software Development 5 02-03-2010 09:48 AM
Static IP for CCTv through DVR CRReddy Networking & Security 1 02-02-2010 05:32 AM
Don't know the advantages of using static IP and it's set up Rup_me Networking & Security 5 15-12-2009 01:18 PM
Static ip and static DNS sawyer Windows Server Help 2 04-11-2009 06:57 PM
What is Global Variable static? Declaring static variable instead of Global variable Reckon Software Development 3 25-04-2009 12:34 PM


All times are GMT +5.5. The time now is 03:35 AM.