I just started using IntelliJ and while creating my first class and method I noticed something. When I wrote GomokuClient(4000); to call on a class from a imported library I of course got a error for the code not being complete, so I pressed the little red bulb to see the issue, and I selected the recommended fix. The fix looked like this:
Now I'm wondering, how do I write the portNumber:label in the parameter myself for other methods. Looked really nice and very helpful, and I'd like to know how to do this myself.
thanks beforehand!
The fix done by the IDE was not about setting parameter label, but instead adding the new() for ensuring the constructor call.
What you additionally see there is a feature of IntelliJ to show method's parameter hints/labels for easy understanding (readability) of the code. You can read more about parameter hints here: https://www.jetbrains.com/help/webstorm/viewing-method-parameter-information.html.
Related
I am currently using Eclipse to code Java with. Recently my lecturer noticed that my print statements in my Java is weird and he does not know a fix to it. It shows System.outprintln() instead of System.out.println(). When I change it to System.out.println() it is underlined with a red line.
Is there a quick fix? He says that I might get marks deducted if I submit my codes in this format without changing it.
Try to use full named class:
java.lang.System.out.println("some value");
If this case would work correctly - you have some mistake with class naming (possibly in manner like in Andy Turner's comment)
PS It would be much easier to assume the reason of problem if you'll provide sketches of your sources.
out is static data member of System class having type of PrintStream.
println() is overloaded method of PrintStream class.
System.outprintln() is compiler error.
Try to compile the class using command prompt using the following command- javac myclass.java and then run it using java myclass.
System.outprintln() should throw a compiler error.
Please note that any IDE is user friendly and helps to write your code faster by providing suggestions but your assignments should not be based completely on them. :)
In intellij IDEA, if a method is unused, the method is shown in a gray color. But in some cases, IDEA doesn't grey out the method, but when I check the references of those methods using alt + F7, IDEA says that the method is unused.
Is this a IDEA bug or is there any reason why IDEA wouldn't grey out these specific methods? If it is a bug, is there some workaround to make IDEA identify that method is unused?
Most likely it's not a bug, it's a limitation for performance reasons. Methods likely to take a long time when searching for usages are skipped.
A workaround is to run Unused Declaration inspection explicitly in all your project via Analyze | Inspect Code or Analyze | Run Inspection by Name. That'll take some time. You can also set up TeamCity server to do it for you automatically every night.
I used to have it working like charm, but one time, I by mistake clicked on alt+Enter on an unused method, and chose to suppress the inspection on unused code. Ever since then, I stopped getting the grayed out methods and code, so since there is a way to get it undone, there sure must be a way to get it back working.
After 5 minutes of searching, I found a solution:
Settings --> Editor --> Inspections --> Java --> Declaration Redundancy --> Unused Declaration
Make sure you check "Unused Declaration"
And I just checked by creating a new useless method, working like a charm.
My answer is quite late, but perhaps it will help others to identify their problem:
IntelliJ didn't mark methods as unused for me, because they were overloaded methods, for example:
1: methodName(String argument)
2: methodName(ArrayList<String> argument)
The first method was no longer used, but the second method was. IntelliJ (I assume) simply checks the method names, and sees that the method name is used, even though one of them is no longer used.
I have checked the other answers on this page for finding unused methods, but have not found a solution to filter out unused, overloaded methods.
It might be a bug if you're using a method with a very common name.
If you tried #Peter Gromov method above, and your method is still yellow, it might be the case that this is a bug.
I had a very common named method, named "stop".
Looking for usages (using ALT + F7) didn't show anything.
Analyzing the whole project, clearly showed that this method did not have any use.
Despite that, the method was still yellow.
I was surprised to find out, that if I try to refactor the method name, I get a pop-up warning that this will change in other places as well.
Turns out, that the refactoring warned about changing the method name in TODO comments. Somehow Lint recognized the TODO comments as using this method.
My advice is to just not name your methods as something that may be written in a TODO comment.
See this image, where I am using a method named "stop" :
my scenario is: I have a class named "A.java", but now I'm realizing that "A" is not appropriate any more, so, I have changed it for "B.java", after I did this, I tried to create a code review for this change and other internal changes for that class, but I faced with an obviously thing: code Collaborator tool creates two different files and clearly it doesn't show as one, like I need it, would be great have a good suggestion, thanks in advance!
Ps: I've tried changing only the file name but this is causing various issues...
I'm trying to work on the CS project where I have to draw a bunch of shapes using a "Turtle" library. However, When I try to call upon the method to be used, it gives me and error. I'm pretty sure it has to do with the method parameters, which I'm just learning about now and still don't usually know which to put in. Any advice?![enter image description here][1]
http://i.stack.imgur.com/Yn32y.png
You don't have to specify the parameter type at the method call, so remove Turtle from drawRectangle(Turtle tParam), it should be like this - drawRectangle(tParam)
The error refers to a problem in your program's code. Specifically you forgot to close a bracket somewhere.
How can I fix this? Eclipse doesn't recognize this function:
listFiles(Filter paramFileFilter)
See these screenshots:
Check the type of FileFilter; chances are that it's not java.io.FileFilter
In such cases always check the import statements for the involved method and arguments. Chances are high you imported some x.y.FileFilter, but wanted a.b.FileFilter. You can most easily do the check by hovering over the identifiers and the method call, where you will see the fully qualified name.
This error happens mostly when using the wrong quick fix when creating those imports in Eclipse, so make sure to select the correct "Import XYZ" quick fix by looking at the package name in braces at the end of the tool tip.
Many years later, but I just hit this same problem myself. My problem was that I created a file filter to use with JFileChooser, and then I tried to use the same filter with File.listFiles. The problem is that there are two different classes both called "FileFilter", or rather, a class and an interface.
JFileChooser uses javax.swing.filechooser.FileFilter. File.listFiles uses java.io.FileFilter.
But fortunately, both require a function with signature public boolean accept(File f). So the solution is easy enough. I change my file filter from "extends javax.swing.filechooser.FileFilter" to "extends javax.swing.filechooser.FileFilter implements java.io.FileFilter". Then it works for both cases.