Необработанное использование параметризованного класса в JavaJAVA

Программисты JAVA общаются здесь
Ответить
Anonymous
 Необработанное использование параметризованного класса в Java

Сообщение Anonymous »

У меня есть два класса, которые используют дженерики в Java для выполнения преобразований между единицами измерения. В классе BaseUnitConverter у меня есть два предупреждения от Intellij IDE, которые говорят:

Код: Выделить всё

Raw use of parameterized class 'InstantiatorUnitConverter'
Unchecked assignment: 'org.cnr.lambertools.utils.unitconverter.InstantiatorUnitConverter' to 'org.cnr.lambertools.utils.unitconverter.InstantiatorUnitConverter'
Unchecked call to 'InstantiatorUnitConverter(Object, T, String)' as a member of raw type 'org.cnr.lambertools.utils.unitconverter.InstantiatorUnitConverter'
для методов:

Код: Выделить всё

protected final  M storeValue(M t, double value, E tt){
me = new InstantiatorUnitConverter(value, tt, st(tt));
return t;
}
и

Код: Выделить всё

protected final  M storeValue(M t, Object value, E tt){
me = new InstantiatorUnitConverter(value, tt, st(tt));
return t;
}
Изображение

Основными классами этой системы преобразования являются следующие:

Код: Выделить всё

import java.io.Serializable;

/**
* Instantiated variables from new UnitConverter instance (Only used in class BaseUnitConverter).
*/
public final class InstantiatorUnitConverter implements Serializable {
private final Object o;      //Only used in DataType and NumericBase measurements (classes), user passed "from" value (Object). When this is the case, variable "v" is not used.
private final double v;      //User passed "from" value (double). When this is the case, variable "o" is not used.
private final T t;        //Enum constant value representing the "from" method of the measurement used.
private final String ts;  //String value of enum constant representing the "from" method of the measurement used.
private final boolean d;  //Used in class B.java "getValuePassed()".  True if "from" value was a double, false for Object (Object only used in DataType and NumericBase measurements (classes)).

/**
* Empty constructor only called when instantiating from class B.java
*/
public InstantiatorUnitConverter(){
o = "";
v = -1;
t = null;
ts = "";
d = true;
}

/**
* Only used in class B.java when measurement "from" method only converts numbers.
* All measurements other than DataType and NumericBase use this constructor.
* @param value User passed "from" value (double).
* @param enumConstant Enum constant value representing the "from" method of the measurement used.
* @param enumTag String value of enum constant representing the "from" method of the measurement used.
*/
public InstantiatorUnitConverter(double value, T enumConstant, String enumTag){
o = "";     //This variable (Object value) will not be used when this constructor is called, default it to an empty string.
v = value;
t = enumConstant;
ts = enumTag;
d = true;   //Variable d set to true as "from" value passed is a numeric type not an Object.
}

/**
* Only used in class B.java when measurement "from" method can convert more than numbers and an Object is passed as the value.
* Only measurements DataType and NumericBase use this constructor.
* @param value User passed "from" value (Object).
* @param enumConstant Enum constant value representing the "from" method of the measurement used.
* @param enumTag String value of enum constant representing the "from" method of the measurement used.
*/
public InstantiatorUnitConverter(Object value, T enumConstant, String enumTag){
o = value;
v = -1;     //This variable (double value) will not be used when this constructor is called, default it to -1
t = enumConstant;
ts = enumTag;
d = false;  //Variable d set to false as "from" value passed is an Object not double.
}

public Object getO() {
return o;
}

public double getV() {
return v;
}

public T getT() {
return t;
}

public String getTs() {
return ts;
}

public boolean isD() {
return d;
}
}
и

Код: Выделить всё

import java.io.Serializable;

/**
* Generic base class for most UnitConverter measurement classes.
*/
public class BaseUnitConverter implements Serializable {

private InstantiatorUnitConverter me; //Instantiate class A.java for variables needed to perform conversions.

public BaseUnitConverter() {
this.me = new InstantiatorUnitConverter();
}

public InstantiatorUnitConverter getIstantiator(){
return this.me;
}

/**
* Returns value initially passed into the measurement's "from" method.
*/
public final Object getValuePassed(){
return (me.isD()) ? me.getV() : me.getO();    //true returns numeric value passed, false returns Object passed.
}

/**
* Returns the enum constant value representing the "from" method of the measurement used.
*/
public final String getTypeConstantPassed(){

return me.getTs();
}

/**
* Stores the needed values to do conversions of the measurement.
* This overload of the method is used in "from" methods in every measurement class other than Anything(), DataType(), and NumericBase().
*
* @param  Class context of measurement passed (usually "this" is passed from caller).
* @param  Enum constant value representing the "from" method of the measurement used.
* @param t Class context of measurement passed (usually "this" is passed from caller).
* @param value User passed "from" value (double).
* @param tt Enum constant value representing the "from" method of the measurement used.
* @return class context passed in so variable like "UnitOf.Length len" can be used as the variable type
*/
protected final   M storeValue(M t, double value, E tt){
me = new InstantiatorUnitConverter(value, tt, st(tt));
return t;
}

/**
* Stores the needed values to do conversions of the measurement.
* This overload of the method is used only in DataType and NumericBase as Objects can be passed as "from" values.
*
* @param  Class context of measurement passed (usually "this" is passed from caller).
* @param  Enum constant value representing the "from" method of the measurement used.
* @param t Class context of measurement passed (usually "this" is passed from caller).
* @param value User passed "from" value (Object).
* @param tt Enum constant value representing the "from" method of the measurement used.
* @return class context passed in so variable like "UnitOf.DataType dt" can be used as the variable type
*/
protected final  M storeValue(M t, Object value, E tt){
me = new InstantiatorUnitConverter(value, tt, st(tt));
return t;
}

/**
* Gets and returns the string value of constant representing the "from" method of the measurement used.
*/
private  String st(E tt){
String unitType = "";
try{
unitType = tt.toString();
} catch(Exception ignored){ }
return unitType;
}

/**
* Used by every measurement class that converts just numbers (Anything(), DataType(), NumericBase() do not apply here).
* Method performs the full conversion of taking the user defined "from" value and converting it into the user desired "to" value.
* @param a Enum constant value of "to" unit. Unit being converted into conversion constant value.
* @param b Enum constant value of "from" unit. Unit starting from conversion constant value.
* @return Finished conversion. "From" converted into "to" value.
*/
protected final double k(double a, double b){

return k(a,b,true);
}

/**
* Used by every measurement class that converts just numbers (Anything(), DataType(), NumericBase() do not apply here)
* Method performs the full conversion of taking the user defined "from" value and converting it into the user desired "to" value.
* @param a Enum constant value of "to" unit. Unit being converted into conversion constant value.
* @param b Enum constant value of "from" unit. Unit starting from conversion constant value.
* @param q Multiply then divide conversion algorithm, false will divide then multiply when converting "to"
* @return Finished conversion. "from" converted into "to" value.
*/
protected final double k(double a, double b, boolean q){

return UnitConverterUtils.i(UnitConverterUtils.i(me.getV(), a, q), b, !q);
}

}
Я попробовал решение, предложенное Сергом Васильчаком, но получил сообщение об ошибке (обратите внимание, просто измените буквенные символы):
Изображение

Изображение


Подробнее здесь: https://stackoverflow.com/questions/766 ... ss-in-java
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «JAVA»