DefaultCategoryDataset addValue

A free public discussion forum for the JFreeChart class library.

DefaultCategoryDataset addValue

Postby tarvid » Wed Apr 30, 2008 10:18 pm

www jfree org/jfreechart/api/javadoc/org/jfree/data/category/DefaultCategoryDataset.html

void addValue(double value, java.lang.Comparable rowKey, java.lang.Comparable columnKey)
Adds a value to the table.
void addValue(java.lang.Number value, java.lang.Comparable rowKey, java.lang.Comparable columnKey)
Adds a value to the table.

Two methods with the same name causing me grief in NetBeans.

Shouldn't they be different?
tarvid
 
Posts: 4
Joined: Fri Apr 18, 2008 1:09 pm

Re: DefaultCategoryDataset addValue

Postby RichardWest » Wed Apr 30, 2008 10:40 pm

tarvid wrote:Shouldn't they be different?


They are different. The first takes a double argument, and the second takes a Number argument. The signatures of these methods are different, so there should not be a name conflict.
Richard West
Design Engineer II
Advanced Micro Devices
Sunnyvale, CA
RichardWest
 
Posts: 844
Joined: Fri Oct 13, 2006 9:29 pm
Location: Sunnyvale, CA

NetBeans says !

Postby tarvid » Wed Apr 30, 2008 11:00 pm

reference to addValue is ambiguous ...

both ...number and double match

and then I get a compiler error

java sun com/docs/books/tutorial/java/javaOO/methods.html

I know you are supposed to be able to name two methods with the same name but different argument lists but in this case I get an error.

DefaultCategoryDataset dataset = new DefaultCategoryDataset();
double x=1.2;
dataset.addValue(x,1,1);
tarvid
 
Posts: 4
Joined: Fri Apr 18, 2008 1:09 pm

Postby RichardWest » Wed Apr 30, 2008 11:05 pm

What if you explicitly typecase the argument as Number or double in the function call? This must be a NetBeans oddity since this works in every programming paradigm I have used. Granted, I have never used NetBeans, so there might be a caveat that I am just unawear of.
Richard West
Design Engineer II
Advanced Micro Devices
Sunnyvale, CA
RichardWest
 
Posts: 844
Joined: Fri Oct 13, 2006 9:29 pm
Location: Sunnyvale, CA

Re: NetBeans says !

Postby david.gilbert » Thu May 01, 2008 8:42 am

tarvid wrote: dataset.addValue(x,1,1);


This seems to be related to autoboxing/unboxing, and my guess is that it is either a bug or a "quirk" in the way autoboxing/unboxing works (but I'm not sure, because most of the time I'm still a Java 1.3 programmer so I haven't really studied this "new" feature).

If you change the above line to:

Code: Select all
dataset.addValue(x, "1", "1");


...the compile problem goes away. For whatever reason, the auto-conversion of the two int primitives into Integer objects (required to match the method signature which requires instances of Comparable for the column and row keys) somehow results in the compiler now being unable to handle the fact that 'x' can be either a double or a Number. But if you supply Strings for the keys, now the compiler doesn't mind that it could either convert the 'x' to a Double (Number) or leave it as a double primitive. Strange.
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Ask your company to buy the JFreeChart Developer Guide
:idea: Check out other products sold by my company Object Refinery Limited
david.gilbert
JFreeChart Project Leader
 
Posts: 11383
Joined: Fri Mar 14, 2003 10:29 am

Postby david.gilbert » Thu May 01, 2008 8:44 am

It would be worth checking if this problem occurs only in NetBeans (in which case, file a bug with them) or if the 'javac' compiler also chokes on it. I'll come back to that if I find some time.
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Ask your company to buy the JFreeChart Developer Guide
:idea: Check out other products sold by my company Object Refinery Limited
david.gilbert
JFreeChart Project Leader
 
Posts: 11383
Joined: Fri Mar 14, 2003 10:29 am

Postby david.gilbert » Thu May 01, 2008 2:36 pm

I can reproduce the bug / quirk in Eclipse as well.
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Ask your company to buy the JFreeChart Developer Guide
:idea: Check out other products sold by my company Object Refinery Limited
david.gilbert
JFreeChart Project Leader
 
Posts: 11383
Joined: Fri Mar 14, 2003 10:29 am

Incorrect second and third arguments

Postby tarvid » Thu May 01, 2008 2:40 pm

Supplying second and third "correct arguments" removes the compile error.

The compile error led me to focus on the first argument which is not the problem.

Chalk this one up to a confused user.

Jim
tarvid
 
Posts: 4
Joined: Fri Apr 18, 2008 1:09 pm

Postby david.gilbert » Thu May 01, 2008 2:46 pm

Intuitively, auto-unboxing ought to make this work though, so it is still a compiler quirk at the least, if not an outright bug. Anyway, glad it is working for you now.
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Ask your company to buy the JFreeChart Developer Guide
:idea: Check out other products sold by my company Object Refinery Limited
david.gilbert
JFreeChart Project Leader
 
Posts: 11383
Joined: Fri Mar 14, 2003 10:29 am


Return to JFreeChart - General

Who is online

Users browsing this forum: Bing [Bot], Google [Bot], Yahoo [Bot] and 11 guests