我有一个编译错误,让我有点难过。它说:
TTTree<K,V>
无法在下面标记的代码行中转换为TTTree<K,V>
。
public abstract class TTTree<K extends Comparable<K>, V> {
public abstract TTTree<K, V> put(K k, V v);
private static <K extends Comparable<K>, V> TTTree<K, V> leaf(K k, V v) { return null; }
private static class Leaf<K extends Comparable<K>, V> extends TTTree<K, V> {
private final K k = null;
private final V v = null;
@Override
public TTTree<K, V> put(K ik, V iv) {
TTTree<K, V> newLeaf = leaf(ik, iv);
return node(newLeaf, k, this); // <---- !!!! ERROR !!!!
}
};
private TTTree<K, V> node(TTTree<K, V> l, K k, TTTree<K, V> r) {
return null;
}
}
似乎这应该有用,那么为什么编译器不喜欢呢?我该怎么做才能解决错误(我想我可以将所有内容转换为原始类型,但这有点过于激烈)。
PS:示例代码减少到'最低限度',同时仍然产生错误。
PS2:使用Java 8编译器进行编译。
答案 0 :(得分:0)
a:5:{i:0;s:40:"Cannot retrieve payment method instance.";i:1;s:2785:"#0 /home/tigerbaygiftsco/public_html/app/code/core/Mage/Payment/Model/Info.php(83): Mage::throwException('Cannot retrieve...')
#1 /home/tigerbaygiftsco/public_html/app/code/core/Mage/Sales/Model/Quote/Payment.php(216): Mage_Payment_Model_Info->getMethodInstance()
#2 /home/tigerbaygiftsco/public_html/app/code/core/Mage/Payment/Block/Info/Container.php(60): Mage_Sales_Model_Quote_Payment->getMethodInstance()
#3 /home/tigerbaygiftsco/public_html/app/code/core/Mage/Payment/Block/Info/Container.php(45): Mage_Payment_Block_Info_Container->_getInfoBlockName()
#4 /home/tigerbaygiftsco/public_html/app/code/core/Mage/Core/Block/Abstract.php(238): Mage_Payment_Block_Info_Container->_prepareLayout()
#5 /home/tigerbaygiftsco/public_html/app/code/core/Mage/Core/Model/Layout.php(430): Mage_Core_Block_Abstract->setLayout(Object(Mage_Core_Model_Layout))
#6 /home/tigerbaygiftsco/public_html/app/code/core/Mage/Core/Model/Layout.php(446): Mage_Core_Model_Layout->createBlock('checkout/onepag...', 'payment_info')
#7 /home/tigerbaygiftsco/public_html/app/code/core/Mage/Core/Model/Layout.php(238): Mage_Core_Model_Layout->addBlock('checkout/onepag...', 'payment_info')
#8 /home/tigerbaygiftsco/public_html/app/code/core/Mage/Core/Model/Layout.php(204): Mage_Core_Model_Layout->_generateBlock(Object(Mage_Core_Model_Layout_Element), Object(Mage_Core_Model_Layout_Element))
#9 /home/tigerbaygiftsco/public_html/app/code/core/Mage/Core/Model/Layout.php(205): Mage_Core_Model_Layout->generateBlocks(Object(Mage_Core_Model_Layout_Element))
#10 /home/tigerbaygiftsco/public_html/app/code/core/Mage/Core/Controller/Varien/Action.php(345): Mage_Core_Model_Layout->generateBlocks()
#11 /home/tigerbaygiftsco/public_html/app/code/core/Mage/Core/Controller/Varien/Action.php(270): Mage_Core_Controller_Varien_Action->generateLayoutBlocks()
#12 /home/tigerbaygiftsco/public_html/app/code/core/Mage/Checkout/controllers/OnepageController.php(186): Mage_Core_Controller_Varien_Action->loadLayout(false)
#13 /home/tigerbaygiftsco/public_html/app/code/core/Mage/Core/Controller/Varien/Action.php(420): Mage_Checkout_OnepageController->progressAction()
#14 /home/tigerbaygiftsco/public_html/app/code/core/Mage/Core/Controller/Varien/Router/Standard.php(250): Mage_Core_Controller_Varien_Action->dispatch('progress')
#15 /home/tigerbaygiftsco/public_html/app/code/core/Mage/Core/Controller/Varien/Front.php(176): Mage_Core_Controller_Varien_Router_Standard->match(Object(Mage_Core_Controller_Request_Http))
#16 /home/tigerbaygiftsco/public_html/app/code/core/Mage/Core/Model/App.php(349): Mage_Core_Controller_Varien_Front->dispatch()
#17 /home/tigerbaygiftsco/public_html/app/Mage.php(640): Mage_Core_Model_App->run(Array)
#18 /home/tigerbaygiftsco/public_html/index.php(80): Mage::run('', 'store')
#19 {main}";s:3:"url";s:27:"/checkout/onepage/progress/";s:11:"script_name";s:10:"/index.php";s:4:"skin";s:7:"default";}
Leaf是一个嵌套的静态类。它对TTTree及其泛型类型一无所知。此外,Leaf :: put方法调用TTTree :: node方法,该方法不是静态的,但属于某个TTTree实例。在调用Leaf :: put时,没有指向您正在调用节点方法的TTTree实例的链接。所以方法TTTree :: node应该是静态的。最后一件事:因为TTTree :: node是静态的,你应该声明与你在Leaf类中使用的相同的类型边界