The syntax sugar provided by Java's enum facility can sometimes be a little confusing. Consider this example, which does not compile:
public enum TestEnum {
FOO("foo") {
...
|
I am using a package that has a method call that is non-static.
It will not let me call this method from a static context.
I can't change the non-static method, how ... |
In StringBuilder class I can do like this:
StringBuilder sb = new StringBuilder();
sb.append( "asd").append(34);
method append returns StringBuilder instance, and I can continuosly call that.
My question is it possible to do so in ... |
I've just started to learn java and I'm having some problem with static/non-static. The problem with my code is within the actionlistener. When I try to compile it, it says
non-static method ... |
I'm using this code to try to print an Array, and using this code void display(){ Iterator listIterator = D.iterator(); while(listIterator.hasNext()) { Disk printDisk =(Disk) listIterator.next(); System.out.println(Disk.toString()); } } however, I get the classic method toString cannot be referenced from a static context error. Not sure what I can do about this. Thanks |
|
Yeah checked it....i never came across this type.....it does work... and one more thing i din't read the question properly. Original code the method is not static and thus the null reference won't work. But yes thanks David..... Everthing we learn something new. Java is vast. Even if we know complex things, some simple things always pass by. |
|
Hello people, im trying to load the characters from a String word into an array, however i am getting an error while trying to use the String field from another class to the class which would load this words characters in an array. Here is my code for the String value represented by the field "targetWord" which i need to use ... |
Well; I was going to use an array to keep track of all sockets and info about connected players such as their name. Now, because the system is creating a new class for each connection, and I plan to add even more classes, I think it's good to have some circularity.. warnerja (post 7): Is that really a good idea? I ... |
|
|
Is it basically that I can't use the new operator in my main function because main functions have to be static in java? What's the deal here? I had this app working as a Java SERVLET, so all i had to do to port it over was replace the doGet method with main and remove all references to servlet specific stuff, ... |
If you check the brackets with a magnifier, it is an inner class. This is not important. @OP - I feel that you are too novice in Java to place two classes in the same file (inner or top level). This will cause all kind of problems that will just obscure your learning, for now. Place each class in a separate ... |
|
When you are in a static context theare is no instance and "this" refers to instance. When you use methodCall(this) you are using the current instance as the parameter, but youre context is not an instance. PD: Sorry about my english.... I like the forum but I'm starting to feel I'm not helping anybody... I've got to study some english beside ... |
|
|
Any statement or expression inside the static method is said to "occur in a static context". In such a method - like the traditional main() method - only static members and methods can be used. (Statements and expressions occuring in lots of other places are also said to occur in a static context - see the JLS http://java.sun.com/docs/books/jls/third_edition/html/classes.html#296300 for details. In ... |
ah, it works if i change jump() to static i was now wondering how to make the user interface work with this ethod in the Game() class private void goRoom(Command command) { if(!command.hasSecondWord()) { // if there is no second word, we don't know where to go... System.out.println("Go where?"); return; } String direction = command.getSecondWord(); // Try to leave current room. ... |