|
| |||||||||
| Tags: access modifiers, default, no static, references, static |
![]() |
| | Thread Tools | Search this Thread |
|
#1
| |||
| |||
| 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); Last edited by Aaliya Seth : 02-03-2010 at 11:13 AM. |
|
#2
| |||
| |||
| 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); Last edited by NetWorkInG : 02-03-2010 at 11:15 AM. |
|
#3
| |||
| |||
| 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. |
|
#4
| |||
| |||
| 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. |
|
#5
| |||
| |||
| 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. |
|
#6
| |||
| |||
| 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()
{
}
} |
![]() |
|
| Thread Tools | Search this Thread |
| |
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 |