package developerworks.ajax.store;
import java.util.*;
// Referenced classes of package developerworks.ajax.store:
// CatalogueDAO, Item, Utils
public class Cart
{
public Cart()
{
totalPrice = 0;
contents = new HashMap();
}
public Cart addItemToCart(String itemId)
{
Item item = (new CatalogueDAO()).getItem(itemId);
if(item != null)
{
totalPrice += item.getPrice();
int newQuantity = 1;
Integer oldQuantity = (Integer)contents.get(item);
if(oldQuantity != null)
newQuantity += oldQuantity.intValue();
contents.put(item, new Integer(newQuantity));
}
return this;
}
public Cart getCart()
{
return this;
}
public int getTotalPrice()
{
return totalPrice;
}
public String getFormattedTotalPrice()
{
return Utils.formatCurrency(totalPrice);
}
public Map getSimpleContents()
{
Map simpleContents = new HashMap();
Item item;
for(Iterator I = contents.keySet().iterator(); I.hasNext(); simpleContents.put(item.getName(), contents.get(item)))
item = (Item)I.next();
return simpleContents;
}
private Map contents;
private int totalPrice;
}
而我拷贝的class文件却是这样的:
package developerworks.ajax.store;
public class Cart
{
public Cart()
{
throw new Error("Unresolved compilation problems: \n\tThe type Map is not generic; it cannot be parameterized with arguments
}
public Cart addItemToCart(String itemId)
{
throw new Error("Unresolved compilation problems: \n\tcontents cannot be resolved\n\tcontents cannot be resolved\n");
}
public Cart getCart()
{
throw new Error("Unresolved compilation problem: \n");
}
public int getTotalPrice()
{
throw new Error("Unresolved compilation problem: \n");
}
public String getFormattedTotalPrice()
{
throw new Error("Unresolved compilation problem: \n");
}
private int totalPrice;
}
而在html中弹出的也正是上面的Error。我的第一反映就是加了密了。以前也听说过什么加密,防止反编译。可是没想到今天让我这个菜鸟给遇上了。其实我想如果是个大虾,也许根本不遇不到这个问题,因为他直接就build 或者用war文件来建,(或许还有更好的方法,有的话在回复时能告诉小弟)。可是就是我这个菜鸟,而且用了拷贝粘帖方法的菜鸟给遇上了。好了,问题解决了,我的文章也快完了。
大家在看完了这篇文章后感觉这写的是什么吗,一点技术含量都没有,是的,可是就是这些没有一点技术含量的问题,却成为我们这些初学者最大的拌脚石,很多人可能就是因为这些小问题而对java望而却步,不再对java深入研究。其实,本身不在于问题是否简单,而在于问题是不是给你造成了障碍,让你无法继续进行研究,这也是我发表这篇文章的目的。如何帮助我们初学者扫清障碍,让我们度过这个难关,有更多时间来学习技术,而不是找一些低级错误。
所以我希望各位大虾在看完我的文章,笑的捧腹之余,也能理解我们这些菜鸟的无奈。最好是多写一些经验性的文章,也就不枉我这么多口舌在这边老老叨叨了。