cancel
Showing results for 
Search instead for 
Did you mean: 

How to handle type safety when using com.sap.typeservices.IProposalList

Former Member
0 Kudos

Hi,

I have been testing out the new features in Web Dynpro Java CE EHP1 using a scenario with BPM and SAP MDM. One of the new features I tested is the Ajax feature of using suggestion values. I have an InputField UI element which have bound to a context attribute (CountriesView/Country) which is of type string. The UI element has the "suggestValues" value set to true. I then use the IProposalList to produce a valueset. This will make the InputField UI appear as a combo box and allow the users to type in a few characters and utilize the Ajax framework to automatically search in the list of values.

The following code works perfectly ok but I don't understand how I should handle the compiler warning "IProposalList is a raw type. References to generic type IProposalList<T> should be parameterized"?

IProposalList proposalsCountry = wdContext.nodeCountriesView().getNodeInfo().getAttribute(IPrivateComp1.ICountriesViewElement.COUNTRY).getModifiableSimpleType().getSVServices().getProposals();

for(int i=0;i<bua.length;i++){

IPrivateComp1.ICountriesViewElement buaelement=wdContext.createCountriesViewElement();

buaelement.setCountry(bua<i>[0]);

buaelement.setCode(bua<i>[1]);

bualist.add(buaelement);

proposalsCountry.add(bua<i>[0]);

}

wdContext.nodeCountriesView().bind(bualist);

I don't have any issues handling this for other types such as ArrayList. Using the syntax "IProposalList<String> proposalsCountry ...." will handle the "proposalsCountry.add .." part but I still have a warning "Type safety: The expression of type IProposalList needs unchecked conversion to conform to IProposalList<String>"

Any ideas on how to handle this?

Thanks,

Johan

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi,

Eventhough there are no replies to this thread I thought I should update with what I belive is an answer to my question. Excerpt from http://stackoverflow.com/questions/382/what-is-the-meaning-of-the-type-safety-warning-in-certain-jav...

"This warning is there because Java is not actually storing type information at runtime in an object that uses generics. Thus, if 'object' is actually a List<String>, there will be no ClassCastException at runtime except until an item is accessed from the list that doesn't match the generic type defined in the variable. This can cause further complications if items are added to the list with this incorrect generic type information. Any code still holding a reference to the list but with the correct generic type information will now have an inconsistent list. To remove the warning, try:

List<?> list = (List<?>) object;However, note that you will not be able to use certain methods such as add because the compiler doesn't know if you are trying to add an object of incorrect type. The above will work in a lot of situations, but if you have to use add or some similarly restricted method, you will just have to suffer the yellow underline in Eclipse (or a SuppressWarning annotation)."

The last line explain the reason for my issue and the lack of a solution when using add method.

/Johan