TransWikia.com

why am I have to convert

Stack Overflow Asked by Ömer on September 12, 2020

I’m trying to make a custom key with some numbers and stuff for my BidiMap like this

package FNA.ArithmeticsTypes;

public interface ArithmeticsOperations<N>
{
   void division(N number);
   void multiplication(N number);
   
   String getValue();
   ArithmeticsOperations<N> setValue(N value);
   ArithmeticsOperations<N> setValue(int value);
   
}

But when I try to put something it require casting. Why is this type casting required?

package FNA.Repositories;

import FNA.ArithmeticsTypes.ArithmeticsOperations;
import org.apache.commons.collections4.BidiMap;
import org.apache.commons.collections4.bidimap.DualHashBidiMap;

public abstract class BidiDictionary<T extends ArithmeticsOperations<?>,E>
{
   private BidiMap<T,E> dictionary = new DualHashBidiMap<>();
   
   public void registerNewElement(E element)
   {
      if(!dictionary.containsValue(element))
      {
         dictionary.put((T) /*Problem is here*/ typeGenerator().setValue(...)), element);
      }
   }
   
   abstract T typeGenerator();
}

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP