|
Child classes are allowed to "hide" members from their parent classes. It gets annoying, like in this case. Eclipse, at least, can be configured to warn when a member variable or method parameter is hiding another variable.
|
# ¿ Jan 4, 2016 19:05 |
|
|
# ¿ May 9, 2024 14:54 |
|
qntm posted:getClassName bound to A.className, because that's the variable which was in scope when A was initialised... so why doesn't getClassName bind to A.inner when THAT'S in scope? Because it's bound to this.inner. That is, it's polymorphic and uses whatever inner is closest. Methods are polymorphic and variables are not. Declare the variables private and it becomes more obvious what's going on.
|
# ¿ Jan 4, 2016 22:47 |
|
I would jokingly suggest using Live by Experts Exchange, but there's not enough people using it yet to be a good joke.
|
# ¿ Feb 5, 2016 02:49 |
|
Gravity Pike posted:We aggressively use Optionals, and we're very happy with it. It drastically cuts down on NPE's, and clarifies intent in interfaces. Speaking of type erasure, you wouldn't be able to do this with Optional: code:
code:
|
# ¿ Feb 12, 2016 21:32 |
|
And what if setWhatever() needs to do something different when you pass it a null value?
|
# ¿ Feb 12, 2016 23:40 |
|
Assume it's not a setter on a POJO, despite the name I arbitrarily gave it. Like, maybe these processValue() methods have to do something special, like display an error, when you pass in an empty Optional:code:
code:
code:
|
# ¿ Feb 13, 2016 00:19 |
|
Also, do you get to use Java 8 features?
|
# ¿ Feb 14, 2016 23:33 |
|
Now I'm laughing at you, instead!
|
# ¿ Mar 7, 2016 00:03 |
|
Casual poster had already edited in the answer by the time you replied.
|
# ¿ Mar 7, 2016 07:30 |
|
baka kaba posted:#JustJavaThings, but this isn't true right? As far as I remember (phoneposting when I shouldn't be) there's a pool of Integer objects for a certain range of values, and when you do Integer d = 3 it assigns d to the pre-existing object instead of creating a new one. You have to explicitly create a new Integer object if that's what you want. So I just checked the bytecode that line generates and you're right. The autoboxing makes it Integer d = Integer.valueOf(3), which does check a cache for values between -128 and a system property that defaults to 127. I didn't know that, but that's okay; I should never care exactly which Integer instances I'm dealing with.
|
# ¿ Apr 26, 2016 22:16 |
|
I'd probably debug that method and see what gets passed in when you click the button normally, then create an instance of ActionEvent in your test that matches that. I don't know if that counts as valid testing, or what.
|
# ¿ Apr 27, 2016 05:52 |
|
Most of that stuff is internal stuff you can't set. You can call the ActionEvent constructor:code:
But, at that point, you're not really testing much.
|
# ¿ Apr 27, 2016 20:11 |
|
The way the interfaces are currently designed, you could pass anything that implements Contract.View to Contract.Presenter.onCreate(), but you can only pass something that implements MainContract.View to MainContract.Presenter.onCreate(). Types could exist that implement Contract.View, but not MainContract.View, so MainContract.Presenter.onCreate() doesn't cover everything on its own.
|
# ¿ Apr 30, 2016 18:12 |
|
Different how?
|
# ¿ May 11, 2016 18:17 |
|
I mean, I guess you're right, that pre-computing the values is technically a pre-optimization, but I'd be reluctant to approve a pull request that replaced those values with method calls (even though the JIT probably would make them fast).
|
# ¿ May 12, 2016 15:36 |
|
Except don't iterate over a Map's key set, calling Map.get() with each key. Instead, iterate over the Map's entry set and save yourself a pile of lookups.
|
# ¿ Jun 16, 2016 21:38 |
|
Paul MaudDib posted:use StringBuffer Or StringBuilder, so you don't waste processing time on unnecessary thread safely.
|
# ¿ Sep 7, 2016 02:41 |
|
There are tools that let you profile memory usage and inspect the heap and stuff, but I have no idea which ones are "good" these days.
|
# ¿ Sep 7, 2016 05:52 |
|
I think basically everybody at my work is pretty tired of our home-built controller/layout/template/rendering engine and I wouldn't mind seeing if something like Thymeleaf could rescue us. Has anybody used it? (Is this a better question for the webdev thread?)
|
# ¿ Sep 14, 2016 22:27 |
|
It looks like they recently released version 3.0.0 and rewrote their parser so you don't need strict XML any more. We were using JSP when I first started here. It sucked, but like most technologies, we probably weren't using it right!
|
# ¿ Sep 14, 2016 23:54 |
|
Yeah, I'm eager to see if it'll work for our email templating, too, because we have, of course, yet another ancient subsystem that nobody likes handling our email templates. I guess the latest version also added support for CSS and JS templates, which sounds like we could finally get all of that stuff to share the same constants with our Java code, for things like CSS class names.
|
# ¿ Sep 15, 2016 15:57 |
|
The try-catch will probably be a bunch slower than a range check would be, if you expect to be out of range a lot. For the other issue, if nulls are the billion-dollar mistake, List.indexOf() and Map.get() taking Object instead of their parameterized type has got to be worth a couple hundred thousand.
|
# ¿ Oct 5, 2016 02:02 |
|
I spent a couple hours a few days ago trying to figure out why, no matter what I did, turning on Thymeleaf's caching didn't seem to do anything. It finally worked when I used reflection to get the field I needed, set it to be accessible, and set it myself. Then I discovered that turning off JRebel made it work fine. Thanks, JRebel.
|
# ¿ Oct 8, 2016 21:48 |
|
Use try-with-resources blocks for both the Reader and the Writer and you don't have to worry about explicitly closing them!
|
# ¿ Oct 12, 2016 18:52 |
|
IntStream.forEach() takes an IntConsumer, though, so you can't just pass this::action if it doesn't accept an integer parameter. Now you're jumping through hoops to get the signatures to fall in line and you'd be better off just using a normal loop.
|
# ¿ Nov 23, 2016 18:20 |
|
But you only have to write that function once, compared to writing IntStream.range(0,5).forEach(ignored -> this.action()) every time. (You can't use the method reference in that line if it doesn't accept an integer parameter.)
|
# ¿ Nov 23, 2016 19:37 |
|
Volguus posted:And, oh, by the way, the double-checked locking idiom that you have in Locker is wrong. As that article says, only before Java 5 and only if you leave out the volatile keyword.
|
# ¿ Dec 6, 2016 16:23 |
|
The part I really liked about Thymeleaf was that the template can be valid HTML, so our designers could return to them and make changes, even after all the processing hooks were added. You can't do that with JSP.
|
# ¿ Jan 21, 2017 16:50 |
|
For that, you probably either can't use an array or you can't use a stream.
|
# ¿ Feb 4, 2017 21:23 |
|
Are you sure the older JAR went away when you were excluding it? And that no other dependencies were sneaking in old versions? (Whee, dependency hell!)
|
# ¿ Feb 8, 2017 22:07 |
|
Boz0r posted:I have some code that doesn't compile in IntelliJ, but our ant script works fine. I don't get it. Yeah, that's weird. While the JVM spec allows methods to differ only by return type, Java definitely does not, so with the type erasure, those two should clash.
|
# ¿ Feb 21, 2017 06:11 |
|
Yeah, you shouldn't ever compare Strings using ==. Always use String.equals() or you'll get behavior like you're seeing.
|
# ¿ Mar 5, 2017 06:57 |
|
PierreTheMime posted:So I have a report application that pulls data from an API and adding results to a List. At this point everything works fine but I'm looking to increase performance by having the pulls subdivided into multiple threads to save on time. Is using a Collections.SynchronizedList() and a synchronized method for adding items okay or is there a better thread-safe option? This would be running on a server with 1.7. If you don't want to roll your own thread pool, you could use an ExecutorService and submit your tasks to that, instead of adding them to a queue.
|
# ¿ Apr 7, 2017 16:35 |
|
One way or another, you need to keep track of the state of the three bases. If you care which player is on a given base (and if you had a Player class or enum), you could have:code:
code:
At this point, you're starting to pass a lot of state around, so you'll want to start thinking about how all the state fits together. Like, what parts of the game are the same every time you run the simulator? (Does the state of the game need to track who's on each team or just who's up to bat next? Does each team care if it's the home team or does only the game care about that? Stuff like that.)
|
# ¿ Apr 21, 2017 23:42 |
|
Class.getResourceAsStream() should be able to handle things while skipping the URL step.
|
# ¿ Apr 24, 2017 02:05 |
|
Ariong posted:Okay here's something. When I run this code: Only if you're in the src directory when you're running your code. Looks like NetBeans is running your code from the project root.
|
# ¿ Apr 27, 2017 02:23 |
|
MercurialOne posted:I'm learning Java now. You can use the javap command to see what the bytecode looks like. In this case, it looks like this: code:
|
# ¿ May 13, 2017 19:44 |
|
When you say "httpinterface," do you mean the "IHttpService" interface? If so, the problem would be that CustomScanIssue doesn't implement IHttpService, so the @Override annotations are incorrect. That doesn't quite gel with what you're asking about, though. Can you provide more information about the errors you're seeing?
|
# ¿ May 17, 2017 04:29 |
|
Ah, yes, that fun Gotcha. If you're lucky, it throws an exception. If you're unlucky, you get silent, undefined behavior. Yeah, no good reason why that class needs to keep track of any state, rather than pass state around its private methods.
|
# ¿ Jul 14, 2017 02:17 |
|
|
# ¿ May 9, 2024 14:54 |
|
Maybe the class is so old, they don't have good test coverage of it and are afraid to break something? There's a pretty reasonable solution to that problem, of course.
|
# ¿ Jul 14, 2017 18:31 |