Campbell Ritchie wrote:Which class has the setRadius method which actually declares that Exception?
I know you are only doing this as a “what happens if” exercise, which permits you to try anything short of deleting every file on your hard drive, but in real life you would do at least three things differently:-1: Not give the radius to the exception as a field. 2: Not make that exception checked. 3: Use java.lang.IllegalArgumentException instead.
Campbell Ritchie wrote:Which class has the setRadius method which actually declares that Exception?
I know you are only doing this as a “what happens if” exercise, which permits you to try anything short of deleting every file on your hard drive, but in real life you would do at least three things differently:-1: Not give the radius to the exception as a field. 2: Not make that exception checked. 3: Use java.lang.IllegalArgumentException instead.
Jeff Verdegan wrote:
Albert Park wrote:
So we can replace the last line with Rectangle2D bounds = f.getStringBounds(message, new FontRenderContext())?
If that constructor is accessible, and if all the method does is create a new FRC using that constructor, then yes.
However, if the method pulls an existing FRC from a cache, or invokes a different constructor, or does some initialization after creating it and before returning it, then, no, we can't just replace the method call with the constructor.
In fact, there's nothing special about constructors in this situation. In general, we can't replace a method call with some other code unless that code does the same thing as what's in the body of the method.
What exactly is getFontRenderContext method returning here other than making a new object of FontRendercontext class?
We don't know and we don't care, beyond what the documentation tells us. This is one of the reasons for methods to exist--so that we can separate what the operation is (get me an FRC) from how it's done (create a new one, initialize it a certain way, or return one from a cache). And then we can change the "how" without changing the "what" if there's a good reason to do so.
Mansukhdeep Thind wrote:
Winston wrote: There are occasions when getClass() is necessary, but to be honest, I'm surprised that a book is teaching it as the standard approach.
I am curious which book are you studying from. If you learn the wrong methodologies in the first go as a beginner/novice, they leave an imprint on the brain that becomes difficult to erase when you actually get to the correct stuff. Better get your hands on a book which takes the correct approach.
Steve Fahlbusch wrote:
The reason why i created reverse method was to print the letters in the right order. My commonSuffix method compares their suffix from right to left, so if i just print that out, it will print backwards.
That is obvious, but why??? Why do what is provided by the language?