|
View:
New views
4 Messages
—
Rating Filter:
Alert me
|
|
|
Request for help with generics-related compiler warningsGreetings, Wicket Wizards,
I am updating a sample Wicket program from 1.3.6 to 1.4.3 and running into a few generics-related issues. I am hoping you folks can quickly set me straight. My code appears to run successfully and passes its JUnit tests, despite the warnings I would like to remove. The purpose of the code is to demonstrate simple use of Forms, Lists, and Tables and associated testing of these constructs using WicketTester. First off, although you hopefully will not need to, you can download the sample code from here: <http://ics-wicket-examples.googlecode.com/files/wicket-example02-1.0.1106.zip> Unzip, cd into the directory, and type "ant", It should download Ivy, then download Wicket, Jetty, SLF4J, and JUnit, and finally compile the system, generating the following generic-related warnings. Let me now show you what they are: Problem 1: please take a look at line 39 of TablePage.java: <http://code.google.com/p/ics-wicket-examples/source/browse/trunk/example02/src/edu/hawaii/wicket/TablePage.java> The problematic line is: new ListDataProvider(contacts) and obviously requires a generic argument, but neither of the following work: new ListDataProvider<Contact>(contacts) // my preferred guess new ListDataProvider<List<Contact>>(contacts) The compiler warning is: [javac] TablePage.java:39: warning: [unchecked] unchecked call to ListDataProvider(java.util.List<T>) as a member of the raw type org.apache.wicket.markup.repeater.data.ListDataProvider [javac] new ListDataProvider(contacts)) { [javac] ^ [javac] TablePage.java:39: warning: [unchecked] unchecked conversion [javac] found : org.apache.wicket.markup.repeater.data.ListDataProvider [javac] required: org.apache.wicket.markup.repeater.data.IDataProvider<java.util.List<edu.hawaii.wicket.TablePage.Contact>> [javac] new ListDataProvider(contacts)) { [javac] ^ Problem 2: on line 49 of the same file, TablePage.java: <http://code.google.com/p/ics-wicket-examples/source/browse/trunk/example02/src/edu/hawaii/wicket/TablePage.java> The line is: Contact contact = (Contact) item.getModelObject(); Since the preceding line provides a parameterized declaration of item (Item<List<Contact>> item), I don't understand why I need to cast here. But the code does not compile if I don't. Then, I get the following warning: [javac] TablePage.java:49: warning: [unchecked] unchecked cast [javac] found : java.util.List<edu.hawaii.wicket.TablePage.Contact> [javac] required: edu.hawaii.wicket.TablePage.Contact [javac] Contact contact = (Contact) item.getModelObject(); [javac] ^ Problem 3: WicketTester and generics. I clearly don't understand how to test with WicketTester. Take a look at lines 37-39 of TestListPage: <http://code.google.com/p/ics-wicket-examples/source/browse/trunk/example02/src/edu/hawaii/wicket/TestListPage.java> This is a mess, and generates the following warning: [javac] TestListPage.java:39: warning: [unchecked] unchecked cast [javac] found : capture#294 of ? [javac] required: java.util.List<java.lang.String> [javac] List<String> metaVars = (List<String>) varsModel.getObject(); I have a feeling that my whole approach to getting values out of the table for testing is wrong, but I don't know what the correct approach is. If any of you can give me a hand, the first Mai Tai is on me the next time you are in Hawaii. Thanks! Philip --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@... For additional commands, e-mail: users-help@... |
|
|
Re: Request for help with generics-related compiler warningsThis does not produces any warnings
public class TablePage extends WebPage { /** Support serialization. */ private static final long serialVersionUID = 1L; /** * Creates a page containing a table of Contacts. */ public TablePage() { // Initialize our list of Contact instances. // Use ArrayList, not List, since ArrayList is Serializable. ArrayList<Contact> contacts = new ArrayList<Contact>(); contacts.add(new Contact("Joe Smith", "123 Honu St., Kailua, HI 96734")); contacts.add(new Contact("Sally Forth", "456 Alapapa St., Honolulu, HI 96813")); // Create the dataview to display our list of contact instances. // Note that the following commented out line is OK from a type perspective. // ListDataProvider<Contact> test = new ListDataProvider<Contact>(contacts); // But we can't say new ListDataProvider<Contact> in the next line. Why? DataView<Contact> dataView = new DataView<Contact>("ContactList", new ListDataProvider<Contact>(contacts)) { /** For serialization. */ private static final long serialVersionUID = 1L; /** * Display each row in the table. * * @param item A Contact instance to be displayed. */ public void populateItem(Item<Contact> item) { Contact contact = (Contact) item.getModelObject(); item.add(new Label("Name", contact.getName())); item.add(new Label("Address", contact.getAddress())); } }; // Add the dataview to the TablePage. add(dataView); } /** * An inner class implementing a record of data to be displayed as a row in the table. Package * private so that TestTablePage can access it. * * @author Philip Johnson */ static class Contact implements Serializable { /** Support serialization. */ private static final long serialVersionUID = 2L; private String name; private String address; /** * Create a new contact, given a name and an address. * * @param name The name. * @param address The address. */ public Contact(String name, String address) { this.name = name; this.address = address; } /** * Return the name. * * @return The name of this contact. */ public String getName() { return name; } /** * Return the address of this contact. * * @return The address. */ public String getAddress() { return address; } } } at least on my IDE Best, Ernesto On Sat, Nov 7, 2009 at 9:42 AM, Philip Johnson <johnson@...> wrote: > Greetings, Wicket Wizards, > > I am updating a sample Wicket program from 1.3.6 to 1.4.3 and running into > a few generics-related issues. I am hoping you folks can quickly set me > straight. My code appears to run successfully and passes its JUnit tests, > despite the warnings I would like to remove. The purpose of the code is to > demonstrate simple use of Forms, Lists, and Tables and associated testing of > these constructs using WicketTester. > > First off, although you hopefully will not need to, you can download the > sample code from here: > < > http://ics-wicket-examples.googlecode.com/files/wicket-example02-1.0.1106.zip > > > > Unzip, cd into the directory, and type "ant", It should download Ivy, then > download Wicket, Jetty, SLF4J, and JUnit, and finally compile the system, > generating the following generic-related warnings. Let me now show you > what they are: > > Problem 1: please take a look at line 39 of TablePage.java: > < > http://code.google.com/p/ics-wicket-examples/source/browse/trunk/example02/src/edu/hawaii/wicket/TablePage.java > > > > The problematic line is: > new ListDataProvider(contacts) > > and obviously requires a generic argument, but neither of the following > work: > new ListDataProvider<Contact>(contacts) // my preferred guess > new ListDataProvider<List<Contact>>(contacts) > > The compiler warning is: > [javac] TablePage.java:39: warning: [unchecked] unchecked call to > ListDataProvider(java.util.List<T>) as a member of the raw type > org.apache.wicket.markup.repeater.data.ListDataProvider > [javac] new ListDataProvider(contacts)) { > [javac] ^ > [javac] TablePage.java:39: warning: [unchecked] unchecked conversion > [javac] found : org.apache.wicket.markup.repeater.data.ListDataProvider > [javac] required: > org.apache.wicket.markup.repeater.data.IDataProvider<java.util.List<edu.hawaii.wicket.TablePage.Contact>> > [javac] new ListDataProvider(contacts)) { > [javac] ^ > > Problem 2: on line 49 of the same file, TablePage.java: > < > http://code.google.com/p/ics-wicket-examples/source/browse/trunk/example02/src/edu/hawaii/wicket/TablePage.java > > > > The line is: > Contact contact = (Contact) item.getModelObject(); > > Since the preceding line provides a parameterized declaration of item > (Item<List<Contact>> item), I don't understand why I need to cast here. But > the code does not compile if I don't. Then, I get the following warning: > > [javac] TablePage.java:49: warning: [unchecked] unchecked cast > [javac] found : java.util.List<edu.hawaii.wicket.TablePage.Contact> > [javac] required: edu.hawaii.wicket.TablePage.Contact > [javac] Contact contact = (Contact) item.getModelObject(); > [javac] > ^ > > Problem 3: WicketTester and generics. > > I clearly don't understand how to test with WicketTester. Take a look at > lines 37-39 of TestListPage: > < > http://code.google.com/p/ics-wicket-examples/source/browse/trunk/example02/src/edu/hawaii/wicket/TestListPage.java > > > > This is a mess, and generates the following warning: > [javac] TestListPage.java:39: warning: [unchecked] unchecked cast > [javac] found : capture#294 of ? > [javac] required: java.util.List<java.lang.String> > [javac] List<String> metaVars = (List<String>) varsModel.getObject(); > > I have a feeling that my whole approach to getting values out of the table > for testing is wrong, but I don't know what the correct approach is. > > If any of you can give me a hand, the first Mai Tai is on me the next time > you are in Hawaii. > > Thanks! > Philip > > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: users-unsubscribe@... > For additional commands, e-mail: users-help@... > > |
|
|
Re: Request for help with generics-related compiler warningsand the casting is no longer needed
DataView<Contact> dataView = new DataView<Contact>("ContactList", new ListDataProvider<Contact>(contacts)) { /** For serialization. */ private static final long serialVersionUID = 1L; /** * Display each row in the table. * * @param item A Contact instance to be displayed. */ public void populateItem(Item<Contact> item) { Contact contact = item.getModelObject(); item.add(new Label("Name", contact.getName())); item.add(new Label("Address", contact.getAddress())); } }; Regards, Ernesto On Sat, Nov 7, 2009 at 10:14 AM, Ernesto Reinaldo Barreiro < reiern70@...> wrote: > This does not produces any warnings > > public class TablePage extends WebPage { > > /** Support serialization. */ > private static final long serialVersionUID = 1L; > > /** > * Creates a page containing a table of Contacts. > */ > public TablePage() { > > // Initialize our list of Contact instances. > // Use ArrayList, not List, since ArrayList is Serializable. > ArrayList<Contact> contacts = new ArrayList<Contact>(); > contacts.add(new Contact("Joe Smith", "123 Honu St., Kailua, HI > 96734")); > contacts.add(new Contact("Sally Forth", "456 Alapapa St., Honolulu, HI > 96813")); > > // Create the dataview to display our list of contact instances. > // Note that the following commented out line is OK from a type > perspective. > // ListDataProvider<Contact> test = new > ListDataProvider<Contact>(contacts); > > // But we can't say new ListDataProvider<Contact> in the next line. > Why? > DataView<Contact> dataView = new DataView<Contact>("ContactList", > new ListDataProvider<Contact>(contacts)) { > /** For serialization. */ > private static final long serialVersionUID = 1L; > > /** > * Display each row in the table. > * > * @param item A Contact instance to be displayed. > */ > public void populateItem(Item<Contact> item) { > Contact contact = (Contact) item.getModelObject(); > item.add(new Label("Name", contact.getName())); > item.add(new Label("Address", contact.getAddress())); > } > }; > > // Add the dataview to the TablePage. > add(dataView); > } > > /** > * An inner class implementing a record of data to be displayed as a row > in the table. Package > * private so that TestTablePage can access it. > * > * @author Philip Johnson > */ > static class Contact implements Serializable { > /** Support serialization. */ > private static final long serialVersionUID = 2L; > private String name; > private String address; > > /** > * Create a new contact, given a name and an address. > * > * @param name The name. > * @param address The address. > */ > public Contact(String name, String address) { > this.name = name; > this.address = address; > } > > /** > * Return the name. > * > * @return The name of this contact. > */ > public String getName() { > return name; > } > > /** > * Return the address of this contact. > * > * @return The address. > */ > public String getAddress() { > return address; > } > } > } > > at least on my IDE > > Best, > > Ernesto > > On Sat, Nov 7, 2009 at 9:42 AM, Philip Johnson <johnson@...> wrote: > >> Greetings, Wicket Wizards, >> >> I am updating a sample Wicket program from 1.3.6 to 1.4.3 and running into >> a few generics-related issues. I am hoping you folks can quickly set me >> straight. My code appears to run successfully and passes its JUnit tests, >> despite the warnings I would like to remove. The purpose of the code is to >> demonstrate simple use of Forms, Lists, and Tables and associated testing of >> these constructs using WicketTester. >> >> First off, although you hopefully will not need to, you can download the >> sample code from here: >> < >> http://ics-wicket-examples.googlecode.com/files/wicket-example02-1.0.1106.zip >> > >> >> Unzip, cd into the directory, and type "ant", It should download Ivy, then >> download Wicket, Jetty, SLF4J, and JUnit, and finally compile the system, >> generating the following generic-related warnings. Let me now show you >> what they are: >> >> Problem 1: please take a look at line 39 of TablePage.java: >> < >> http://code.google.com/p/ics-wicket-examples/source/browse/trunk/example02/src/edu/hawaii/wicket/TablePage.java >> > >> >> The problematic line is: >> new ListDataProvider(contacts) >> >> and obviously requires a generic argument, but neither of the following >> work: >> new ListDataProvider<Contact>(contacts) // my preferred guess >> new ListDataProvider<List<Contact>>(contacts) >> >> The compiler warning is: >> [javac] TablePage.java:39: warning: [unchecked] unchecked call to >> ListDataProvider(java.util.List<T>) as a member of the raw type >> org.apache.wicket.markup.repeater.data.ListDataProvider >> [javac] new ListDataProvider(contacts)) { >> [javac] ^ >> [javac] TablePage.java:39: warning: [unchecked] unchecked conversion >> [javac] found : >> org.apache.wicket.markup.repeater.data.ListDataProvider >> [javac] required: >> org.apache.wicket.markup.repeater.data.IDataProvider<java.util.List<edu.hawaii.wicket.TablePage.Contact>> >> [javac] new ListDataProvider(contacts)) { >> [javac] ^ >> >> Problem 2: on line 49 of the same file, TablePage.java: >> < >> http://code.google.com/p/ics-wicket-examples/source/browse/trunk/example02/src/edu/hawaii/wicket/TablePage.java >> > >> >> The line is: >> Contact contact = (Contact) item.getModelObject(); >> >> Since the preceding line provides a parameterized declaration of item >> (Item<List<Contact>> item), I don't understand why I need to cast here. But >> the code does not compile if I don't. Then, I get the following warning: >> >> [javac] TablePage.java:49: warning: [unchecked] unchecked cast >> [javac] found : java.util.List<edu.hawaii.wicket.TablePage.Contact> >> [javac] required: edu.hawaii.wicket.TablePage.Contact >> [javac] Contact contact = (Contact) item.getModelObject(); >> [javac] >> ^ >> >> Problem 3: WicketTester and generics. >> >> I clearly don't understand how to test with WicketTester. Take a look at >> lines 37-39 of TestListPage: >> < >> http://code.google.com/p/ics-wicket-examples/source/browse/trunk/example02/src/edu/hawaii/wicket/TestListPage.java >> > >> >> This is a mess, and generates the following warning: >> [javac] TestListPage.java:39: warning: [unchecked] unchecked cast >> [javac] found : capture#294 of ? >> [javac] required: java.util.List<java.lang.String> >> [javac] List<String> metaVars = (List<String>) >> varsModel.getObject(); >> >> I have a feeling that my whole approach to getting values out of the table >> for testing is wrong, but I don't know what the correct approach is. >> >> If any of you can give me a hand, the first Mai Tai is on me the next time >> you are in Hawaii. >> >> Thanks! >> Philip >> >> >> >> >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: users-unsubscribe@... >> For additional commands, e-mail: users-help@... >> >> > |
|
|
Re: Request for help with generics-related compiler warningsThanks so much, both of you!
Anyone have any ideas about the WicketTester code? Problem 3: WicketTester and generics. I clearly don't understand how to test with WicketTester. Take a look at lines 37-39 of TestListPage: <http://code.google.com/p/ics-wicket-examples/source/browse/trunk/example02/src/edu/hawaii/wicket/TestListPage.java> This is a mess, and generates the following warning: [javac] TestListPage.java:39: warning: [unchecked] unchecked cast [javac] found : capture#294 of ? [javac] required: java.util.List<java.lang.String> [javac] List<String> metaVars = (List<String>) varsModel.getObject(); Cheers, Philip |
| Free embeddable forum powered by Nabble | Forum Help |