|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
主要缺点就是:速度比较慢,没有C和C++快Objective2)
Determinetheresultofapplyingthebooleanequals(Object)methodtoobjectsofanycombinationoftheclassesjava.lang.Stringjava.lang.Booleanandjava.lang.Object.
Theequalsmethodcanbeconsideredtoperformadeepcomparisonofthevalueofanobject,whereasthe==operatorperformsashallowcomparison.Theequalsmethodcompareswhatanobjectpointstoratherthanthepointeritself(ifwecanadmitthatJavahaspointers).
TheequalsmethodappliedtoaString,howeverthatStringwascreated,performsacharacterbycharactercomparison.
Objective3)
Inanexpressioninvolvingtheoperators&|&&||andvariablesofknownvaluesstatewhichoperandsareevaluatedandthevalueoftheexpression.
Objective4)
Determinetheeffectuponobjectsandprimitivevaluesofpassingvariablesintomethodsandperformingassignmentsorothermodifyingoperationsinthatmethod.
UnaryNumericPromotion
Contexts:
・Operandoftheunaryarithmeticoperators+andC
・Operandoftheunaryintegerbit-wisecomplementoperator~
・Duringarraycreation,forexamplenewint[x],wherethedimensionexpressionxmustevaluatetoanintvalue.
・Indexingarrayelements,forexampletable[‘a’],wheretheindexexpressionmustevaluatetoanintvalue.
・Individualoperandsoftheshiftoperators.
Binarynumericpromotion
Contexts:
・Operandsofarithmeticoperators*,/,%,+andC
・Operandsofrelationaloperators<,<=,>and>=
・NumericOperandsofequalityoperators==and!=
・IntegerOperandsofbit-wiseoperators&,^and|
ConversionofPrimitives
1.3typesofconversionCassignmentconversion,methodcallconversionandarithmeticpromotion
2.booleanmaynotbeconvertedto/fromanynon-booleantype.
3.Wideningconversionsaccepted.Narrowingconversionsrejected.
4.byte,shortcan’tbeconvertedtocharandviceversa.
5.Arithmeticpromotion
5.1Unaryoperators
・iftheoperandisbyte,shortorchar{
convertittoint;
}
else{
donothing;noconversionneeded;
}
5.2Binaryoperators
・ifoneoperandisdouble{
alldouble;converttheotheroperandtodouble;
}
elseifoneoperandisfloat{
allfloat;converttheotheroperandtofloat;
}
elseifoneoperandislong{
alllong;converttheotheroperandtolong;
}
else{
allint;convertalltoint;
}
6.Whenassigningaliteralvaluetoavariable,therangeofthevariable’sdatatypeischeckedagainstthevalueoftheliteralandassignmentisallowedorcompilerwillproduceanerror.
charc=3;//thiswillcompile,eventhoughanumericliteralisbydefaultanintsincetherangeofcharwillacceptthevalue
inta=3;
chard=a;//thiswon’tcompile,sincewe’reassigninganinttochar
chare=-1;//thisalsowon’tcompile,sincethevalueisnotintherangeofchar
floatf=1.3;//thiswon’tcompile,eventhoughthevalueiswithinfloatrange.Hererangeisnotimportant,butprecisionis.1.3isbydefaultadouble,soaspecificcastorf=1.3fwillwork.
floatf=1/3;//thiswillcompile,sinceRHSevaluatestoanint.
floatf=1.0/3.0;//thiswon’tcompile,sinceRHSevaluatestoadouble.
7.Alsowhenassigningafinalvariabletoavariable,evenifthefinalvariable’sdatatypeiswiderthanthevariable,ifthevalueiswithintherangeofthevariableanimplicitconversionisdone.
byteb;
finalinta=10;
b=a;//Legal,sincevalueof‘a’isdeterminableandwithinrangeofb
finalintx=a;
b=x;//Legal,sincevalueof‘x’isdeterminableandwithinrangeofb
inty;
finalintz=y;
b=z;//Illegal,sincevalueof‘z’isnotdeterminable
8.Methodcallconversionsalwayslookfortheexactdatatypeorawideroneinthemethodsignatures.Theywillnotdonarrowingconversionstoresolvemethods,insteadwewillgetacompileerror.
Hereisthefigureofallowableprimitiveconversion.
byteàshortàintàlongàfloatàdouble
|
|