我正在尝试制作价格低于给定数量的书籍的 ArrayList,但我不断收到此编译器错误:
JAmos_Chapter09_exercise_94Arrays.java:86: error: double cannot be dereferenced
if ( ( currentJAmos_Chapter09_exercise_94.getPrice( ) ).indexOf( searchString ) != -1 )
^
1 error
在我的数组列表文件的代码中编译此方法后:
public ArrayList<JAmos_Chapter09_exercise_94> searchForPrice( String searchString )
{
ArrayList<JAmos_Chapter09_exercise_94> searchResult = new ArrayList<JAmos_Chapter09_exercise_94>( );
for ( JAmos_Chapter09_exercise_94 currentJAmos_Chapter09_exercise_94 : library )
{
if ( ( currentJAmos_Chapter09_exercise_94.getPrice( ) ).indexOf( searchString ) != -1 )
searchResult.add( currentJAmos_Chapter09_exercise_94 );
}
searchResult.trimToSize( );
return searchResult;
}
我的方法代码的 getPrice 部分从此类文件中获取双精度:
/** default constructor
*/
public JAmos_Chapter09_exercise_94( )
{
title = "";
author = "";
price = 0.0;
}
/** overloaded constructor
* @param newTitle the value to assign to title
* @param newAuthor the value to assign to author
* @param newPrice the value to assign to price
*/
public JustinAmos_Chapter09_exercise_94( String newTitle, String newAuthor, double newPrice )
{
title = newTitle;
author = newAuthor;
price = newPrice;
}
/** getTitle method
* @return the title
*/
public String getTitle( )
{
return title;
}
/** getAuthor method
* @return the author
*/
public String getAuthor( )
{
return author;
}
/** getPrice method
* @return the price
*/
public double getPrice( )
{
return price;
}
/** toString
* @return title, author, and price
*/
public String toString( )
{
return ( "title: " + title + "\t"
+ "author: " + author + "\t"
+ "price: " + price );
}
}
总的来说,我想知道如何摆脱
double 不能被取消引用错误
因为我需要搜索双精度而不是字符串。
对不起,如果这很长。