Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #14292 > unrolled thread
| Started by | "Hiram Hunt" <hiramhunt@verizon.net> |
|---|---|
| First post | 2012-05-05 16:19 -0400 |
| Last post | 2012-05-05 14:16 -0700 |
| Articles | 6 — 4 participants |
Back to article view | Back to comp.lang.java.programmer
JavaFX Slider compile time error "Hiram Hunt" <hiramhunt@verizon.net> - 2012-05-05 16:19 -0400
Re: JavaFX Slider compile time error Leif Roar Moldskred <leifm@dimnakorr.com> - 2012-05-05 15:32 -0500
Re: JavaFX Slider compile time error "Hiram Hunt" <hiramhunt@verizon.net> - 2012-05-05 17:53 -0400
Re: JavaFX Slider compile time error Lew <noone@lewscanon.com> - 2012-05-05 21:03 -0700
Re: JavaFX Slider compile time error Lew <noone@lewscanon.com> - 2012-05-05 21:09 -0700
Re: JavaFX Slider compile time error markspace <-@.> - 2012-05-05 14:16 -0700
| From | "Hiram Hunt" <hiramhunt@verizon.net> |
|---|---|
| Date | 2012-05-05 16:19 -0400 |
| Subject | JavaFX Slider compile time error |
| Message-ID | <4fa58b39$0$41612$c3e8da3$3a1a2348@news.astraweb.com> |
Hello,
I have some code that gets compile time errors in
some places but not others. I don't understand why
one situation is apparently legal and the other is not.
Here is the copy-and-paste of a minimal example:
/*
* Program: Minimal
* A minimal case of some code that is causing
* compile time errors. Compile with Java 7u3 and
* use JavaFX 2.0 library (jfxrt.jar) on 64 bit
* Windows 7.
*/
import javafx.geometry.Orientation;
import javafx.scene.control.Slider;
import javafx.scene.control.SliderBuilder;
class Minimal {
// No compile error on okslider1.
Slider okslider1 = SliderBuilder
.create()
.prefWidth(100.0)
.orientation(Orientation.HORIZONTAL)
.build();
// Swap width and orientation calls; still no compile error.
Slider okslider2 = SliderBuilder
.create()
.orientation(Orientation.HORIZONTAL)
.prefWidth(100.0)
.build();
// Create a SliderBuilder with the setting of several
// properties omitted for the sake of a minimal example.
SliderBuilder sliderbuilder = SliderBuilder
.create();
// Use the SliderBuilder I just made to make a Slider.
// Compile error for badslider1: cannot find method
// .orientation(Orientation) in class ControlBuilder.
Slider badslider1 = sliderbuilder
.prefWidth(100.0)
.orientation(Orientation.HORIZONTAL)
.build();
// Swap width and orientation calls.
// Compile error for badslider2: cannot find method
// .build() in class ControlBuilder. Thus, comparing
// with badslider1 case, the problem seems to be with
// using the result of .prefWidth(), but why doesn't
// the same problem appear when I make okslider1
// and okslider2?
Slider badslider2 = sliderbuilder
.orientation(Orientation.HORIZONTAL)
.prefWidth(100.0)
.build();
}
(End copy-and-paste.)
Can anyone explain this behavior? In particular, I don't just
want to know why the errors occur, but why they don't also occur
in the cases of okslider1 and okslider2. Thanks.
-- Hiram Hunt
[toc] | [next] | [standalone]
| From | Leif Roar Moldskred <leifm@dimnakorr.com> |
|---|---|
| Date | 2012-05-05 15:32 -0500 |
| Message-ID | <APednd33hPX6EzjSnZ2dnUVZ8gudnZ2d@giganews.com> |
| In reply to | #14292 |
Hiram Hunt <hiramhunt@verizon.net> wrote: > Hello, > I have some code that gets compile time errors in > some places but not others. I don't understand why > one situation is apparently legal and the other is not. > Here is the copy-and-paste of a minimal example: I don't have a Java development environment at hand, but it looks like a problem with generics. > // Create a SliderBuilder with the setting of several > // properties omitted for the sake of a minimal example. > > SliderBuilder sliderbuilder = SliderBuilder > .create(); Try "SliderBuilder<?> sliderbuilder =" instead. -- Leif Roar Moldskred
[toc] | [prev] | [next] | [standalone]
| From | "Hiram Hunt" <hiramhunt@verizon.net> |
|---|---|
| Date | 2012-05-05 17:53 -0400 |
| Message-ID | <4fa5a141$0$20320$c3e8da3$9deca2c3@news.astraweb.com> |
| In reply to | #14293 |
"Leif Roar Moldskred" <leifm@dimnakorr.com> wrote in message news:APednd33hPX6EzjSnZ2dnUVZ8gudnZ2d@giganews.com... > Hiram Hunt <hiramhunt@verizon.net> wrote: >> Hello, >> I have some code that gets compile time errors in >> some places but not others. I don't understand why >> one situation is apparently legal and the other is not. >> Here is the copy-and-paste of a minimal example: > > I don't have a Java development environment at hand, but > it looks like a problem with generics. > >> // Create a SliderBuilder with the setting of several >> // properties omitted for the sake of a minimal example. >> >> SliderBuilder sliderbuilder = SliderBuilder >> .create(); > > Try "SliderBuilder<?> sliderbuilder =" instead. > Thanks Leif and Markspace. Using <?> worked both in the minimal example and in the program I trimmed down to make the example. Using SliderBuilder<SliderBuilder> didn't, but thanks also. I understand some of how generic work, but not all. I assume that some type information that is available in the expressions that initialize okslider1 and okslider2 is lost by not including the <?> in "SliderBuilder<?> sliderbuilder". -- Hiram Hunt
[toc] | [prev] | [next] | [standalone]
| From | Lew <noone@lewscanon.com> |
|---|---|
| Date | 2012-05-05 21:03 -0700 |
| Message-ID | <jo4t6p$tj7$1@news.albasani.net> |
| In reply to | #14297 |
On 05/05/2012 02:53 PM, Hiram Hunt wrote: > "Leif Roar Moldskred"<leifm@dimnakorr.com> wrote in message > news:APednd33hPX6EzjSnZ2dnUVZ8gudnZ2d@giganews.com... >> Hiram Hunt<hiramhunt@verizon.net> wrote: >>> Hello, >>> I have some code that gets compile time errors in >>> some places but not others. I don't understand why >>> one situation is apparently legal and the other is not. >>> Here is the copy-and-paste of a minimal example: >> >> I don't have a Java development environment at hand, but >> it looks like a problem with generics. >> >>> // Create a SliderBuilder with the setting of several >>> // properties omitted for the sake of a minimal example. >>> >>> SliderBuilder sliderbuilder = SliderBuilder >>> .create(); >> >> Try "SliderBuilder<?> sliderbuilder =" instead. >> > > Thanks Leif and Markspace. Using<?> worked both in the minimal > example and in the program I trimmed down to make the example. > Using SliderBuilder<SliderBuilder> didn't, but thanks also. > I understand some of how generic work, but not all. I assume > that some type information that is available in the expressions > that initialize okslider1 and okslider2 is lost by not including > the<?> in "SliderBuilder<?> sliderbuilder". Don't assume, research. Generics without generic parameters (the angle-bracket part) are known as "raw" types, and exist only for backward compatibility. They are an error, shown as a warning by compilers in lenient mode. You should regard generic parameters as mandatory in generic types. The wildcard '?' is a dodge to get around not knowing the type at compile time. If you know what the base (generic) type should be, you should specify it. It would be ridiculous for the base type of 'SlicerBuilder' to be 'SliderBuilder', wouldn't it? Admit it, you were just throwing shit at the wall to see what would stick, weren't you? Read the angle brackets as "of": 'SliderBuilder<Foo>' is "'SliderBuilder' of 'Foo'". What is 'SliderBuilder', anyway? Show a link to the Javadocs for it (which *surely* you've studied - right?), please. -- Lew Honi soit qui mal y pense. http://upload.wikimedia.org/wikipedia/commons/c/cf/Friz.jpg
[toc] | [prev] | [next] | [standalone]
| From | Lew <noone@lewscanon.com> |
|---|---|
| Date | 2012-05-05 21:09 -0700 |
| Message-ID | <jo4thk$tst$1@news.albasani.net> |
| In reply to | #14326 |
On 05/05/2012 09:03 PM, Lew wrote: > On 05/05/2012 02:53 PM, Hiram Hunt wrote: >> "Leif Roar Moldskred"<leifm@dimnakorr.com> wrote in message >> news:APednd33hPX6EzjSnZ2dnUVZ8gudnZ2d@giganews.com... >>> Hiram Hunt<hiramhunt@verizon.net> wrote: >>>> Hello, >>>> I have some code that gets compile time errors in >>>> some places but not others. I don't understand why >>>> one situation is apparently legal and the other is not. >>>> Here is the copy-and-paste of a minimal example: >>> >>> I don't have a Java development environment at hand, but >>> it looks like a problem with generics. >>> >>>> // Create a SliderBuilder with the setting of several >>>> // properties omitted for the sake of a minimal example. >>>> >>>> SliderBuilder sliderbuilder = SliderBuilder >>>> .create(); >>> >>> Try "SliderBuilder<?> sliderbuilder =" instead. OK, I finally checked out <http://docs.oracle.com/javafx/2/api/javafx/scene/control/SliderBuilder.html> myself. I was wrong on several counts. Although I was right about the value of the Javadocs. It looks like a similar pattern to 'Enum' or 'Comparable', where the 'B' is the subtype of the 'Builder'. As others have said, the '<?>' is the way to go. -- Lew Honi soit qui mal y pense. http://upload.wikimedia.org/wikipedia/commons/c/cf/Friz.jpg
[toc] | [prev] | [next] | [standalone]
| From | markspace <-@.> |
|---|---|
| Date | 2012-05-05 14:16 -0700 |
| Message-ID | <jo45bs$h2e$1@dont-email.me> |
| In reply to | #14292 |
On 5/5/2012 1:19 PM, Hiram Hunt wrote: > .prefWidth(100.0) > .build(); ::prefWidth() is declared in the BuildControl<B> class, and has as Lief pointed out a generic return type. Its ::create() factory method does return a type of SliderBuilder<?>, so that might be your best best for your variable sliderBuilder. If that doesn't work, try SliderBuilder<SliderBuilder> as the type of sliderBulder. It seems to be to fit more closely with the declared intent (bound) of the type parameter.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.java.programmer
csiph-web