Browsing 7239 questions and answers with Jon Skeet

Opening Java enum method declarations in Eclipse

Eclipse provides a feature to open the declarations of fields, invoked methods etc. (F3 or Right click = Open declaration or Ctrl + click on the invoked method) However, in the...
Jon Skeet
people
quotationmark

Why doesn't Eclipse open the declaration of such enum methods? Because they're not declared in source code at all. They're automatically supplied by the compiler - where would you expect to be taken? Ctrl-clicking on MyEnum (rather... more 4/25/2014 1:15:48 PM

people

Why do I have to cast to type parameter and can't use the constrained type?

Can anyone explain why I have to cast to T and why Add2 does not accept Bar as a parameter? class Foo<T> where T : class, IBar { void Add1(IDo<T> @do) {...
Jon Skeet
people
quotationmark

It may not be appropriate. For example, consider: class Other : Bar {} ... IDo<Other> do = new DoImpl<Other>(); Foo<Other> foo = new Foo<Other>(); foo.Add2(do); With your current code, that would be calling... more 4/25/2014 11:47:26 AM

people

How can I tell using reflection if a class is final

Suppose I have a class: public final class Foo and a reflected Class clz reference that refers to that class. How can I tell (using clz) that Foo is final?
Jon Skeet
people
quotationmark

You use Class.getModifiers(), ideally using the Modifier class to interpret the return value in a readable way: if (Modifier.isFinal(clz.getModifiers()) more 4/25/2014 10:51:15 AM

people

Converting String format to integer is possible..?

i would like to know is it possible to convert the string to int format. eg: i need to store the the textbox value in to the variable state of type int. so, is it possible to...
Jon Skeet
people
quotationmark

Now we have a bit more information It sounds like you don't want to parse a numeric string at all, which is the obvious interpretation of your original question. If you want to map a string to a number, you'll need some sort of... more 4/25/2014 9:19:46 AM

people

Having trouble with calculations... what's wrong?

Having trouble calculating this out. The rest of the coding is fine but this one class. The error focuses on one line. retail_price = double.parseDouble(input1) *...
Jon Skeet
people
quotationmark

The name of the class containing parseDouble is Double, not double. They are not synonyms. double is the name of the primitive type, and primitives do not have methods. So you need: retail_price = Double.parseDouble(input1) *... more 4/25/2014 8:52:22 AM

people

Getting ArgumentOutOfRangeException when calling Bitmap.SetPixel

In some kind of way a not so easy bug has sneaked its way into this little piece of code without my knowledge of fixing it: static void Main(string[] args) { Bitmap bm = new...
Jon Skeet
people
quotationmark

You've created an image with a height and width of 1. Coordinates start at 0, therefore the only valid first two arguments two SetPixel are 0: bm.SetPixel(0, 0, Color.AliceBlue); The only confusing thing is how this could ever have... more 4/24/2014 4:46:54 PM

people

Java Symbol Error

i keep getting this "Error:cannot find symbol" on line 44 and i cant figure out what symbol im missing. im sure that all my variables are declared. Can someone help me find the...
Jon Skeet
people
quotationmark

affichertable is an instance method in personne. You're trying to call it as if it's a static method in popo. You should be calling p1.affirchertable(...) or p2.affichertable(...) at a guess. Alternatively, if the affirchertable method... more 4/24/2014 4:39:57 PM

people

Formatting doubles to two decimal places in Java produces a comma instead of a dot

I have read many threads, and it seems to be the best solution to keep 2 places in my double number: DecimalFormat df = new DecimalFormat("#.00"); double d =...
Jon Skeet
people
quotationmark

If you want a dot rather than a comma, you should specify a Locale which uses dot as the decimal separator, e.g. DecimalFormat df = new DecimalFormat("#.00", ... more 4/24/2014 1:28:24 PM

people

Java HashSet remove(e) method doesn't behave as I expected

I am unable to understand the logic behind it. Case 1: HashSet shortSet = new HashSet(); for (short i = 0; i < 3; i++) { shortSet.add(i); ...
Jon Skeet
people
quotationmark

The problem is that in the first case, the expression i is of type short, whereas the expression i - 1 is of type int. Those values are being boxed to Short and Integer respectively - the Integer isn't in the set, so can't be removed. You... more 4/24/2014 11:02:27 AM

people

JPA TypedQuery: Parameter value element did not match expected type

I am using JPA 2.0 and having following code in DAO layer: public void test() { String key = "status"; String[] statuses = {"A", "B"}; List<TestTable> result =...
Jon Skeet
people
quotationmark

You've got a variable of type Object, and you're calling Arrays.asList. That means you've effectively called: List<Object> values = Arrays.asList(new Object[] {valueArr}); So you're creating a list of a single element, where that... more 4/24/2014 9:32:26 AM

people