Widening Reference Conversion
5.1.4 Widening Reference Conversions
From any array type to type Cloneable.
From any array type to type java.io.Serializable
Why does the following code fail when trying to convert array as mentioned above?
String[] arr1 = new String[] { "hello", "world" };
SomeClass myCloneable = (SomeClass) (arr1);
class SomeClass implements Serializable, Cloneable {
Cannot cast from String[] to SomeClassMessage was edited by:
jp_in_chains
You can think of the inheritance tree like this:
Serializable
Class String[]When casting, you can only go up the tree, never down
it. Since Serializable is above String[], you could
cast String[] to Serializable, like this:
Serializable srsly =
(Serializable)someStringArray;
You can go both up and down, but going up one branch and then down the other will give a ClassCastException at runtime
Similar Messages
-
Reference Conversion Rule?
hi
I need some help in understand - by simple example - the following two reference conversion rules which I read in a java book:
1) A class reference can be converted to:
- Any class reference with a runtime check
- Any interface reference with a runtime check
2) A reference array can be converted to:
- A Cloneable reference
- A Serializable reference
plz., provide me simple examples for each rule,
thank u so much1) A class reference can be converted to:
- Any class reference with a runtime check
- Any interface reference with a runtime
me checkAny downcast (from supertype to subtype) will require a runtime check. It's because that the complier will require you to cast at compile time (and thus resuming full responibility for the conversion) but you may have been lying so the runtime system will check anyway.
For this reason (downcasting is not typesafe but requires a runtime check) it should be avoided.
2) A reference array can be converted to:
- A Cloneable reference
- A Serializable referenceThat's because Cloenable and Serializable are supertypes of every array. You can always upcast any array to any of those.
class MyType {}
MyType[] mt = new MyType[0]; // array type implements Cloneable and Serializabe
Cloneable c = mt; // typesafe upcast to supertype
Serializable s = mt; // typesafe upcast to supertype
mt = (MyType[])s; // not typesafe downcast to subtype (will be checked at runtime) -
Open vi reference conversion from Labview 6 to Labview 2014
Is there a way that someone can help me convert this VI written in Labview 6.1 so that I can work en EXE in Labview 2014.
I succed to open this vi from 6.1 to 2014 but it does not run. The open vi reference those not work in exe program. Someone know how I can replace that function...
Thanks!
Solved!
Go to Solution.
Attachments:
to convert 2104.zip 17 KBError 7 is File Not Found. So your dynamically called VI is not in your executable.
In the build spec for the executable in your project, there is a section for "Source Files". On of the options for the VIs is "Always Include".
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines -
Hi,
the output I get for 2 + 4/5 is 2. I cannot undestand this. I thought, that when we add two primitives and one of them is greater than int then the other will be widened for that type.
In the example above isn't 4/5 a float and shouldn't 2 be also be converted to float making the result to be 2.8 instead ?
Any help will be greatly appreciatedThe division
0 = 4/5
is called an integer division which is legitimate.
You cannot arbitrarily optimize expression when dealing with integers without taking into account of this effect.
On the other hand,
0.8 = 4.0/5.0
is floating number division. -
Casting conversion in JLS3 draft
Seems to be missing a post-boxing widening reference conversion:class C {
Object o1 = (Comparable<Float>)1.0f; // ok
Object o2 = (java.io.Serializable)false; // ok
}Please ignore the Objects on the left-hand-sides - they are there only to give the casts somewhere to exist.
Anyway, "5.5 Casting Conversion" says: "Casting contexts allow the use of ...a boxing conversion (�5.1.7)." but it there is no optional post-boxing widening reference conversion as there is under assignment conversion and method invocation conversion. Given that fact, it seems that those two statements shouldn't compile, or the jls should change.Actually, if you notice, I specifically mention boxing.
You're right that Float->Object ends up as a nop in the bytecode, and it is allowed by the draft jls3.
But float->Float->Object does not work out to a nop in the bytecode - a Float is actually allocated.
In any case, what happens in the bytecode or internally in the compiler is sort of irrelevant, because according to the draft jls3, the two statements in the example should never make it past the compiler.
You can't have a cast of the form (Type)arg if arg's compile-time type is not convertible to Type via "casting conversion"... and "float" is not casting-convertible to "Object" according to the rules of the draft jls3.
Of course, it's probably just an omission in the spec itself and not cause for alarm. -
Static verification of interface references
The JVM spec (prior to JDK 6, to keep it simple) implies that static data-flow-based verification is done on methods at class load time, including the parameters to method calls. For object references (pointers) this, as I understand it, assures than the class flowing to a use of a reference either matches the use exactly or can be "widened" to match the use, based on the "widening reference conversions" described in the language spec.
What I can't figure out is that this definition of "widening" does not appear to be applied to interfaces. Rather, "widening" of interfaces appears to be allowed (for static verification, not necessarily source compilation) somewhat blindly. Only if a method is called on an interface and the method is not implemented by the runtime object does an error appear to be generated.
Is this true? If so, is the behavior documented anywhere?Here is an example of what I'm describing:
package verify;
public class Main
public static void main(String args[]) {
System.out.println("Hello");
foo();
System.out.println("Goodbye");
public static void foo() {
System.out.println("Entered Main.foo");
B b = new rB();
b.methodA();
package verify;
public interface A {
public void methodA();
package verify;
public interface B
// extends A
public void methodB();
package verify;
public class rB implements B {
public void methodA() {
System.out.println("Inside B.methodA");
public void methodB() {
System.out.println("Inside B.methodB");
The above is compiled initially with the commented lines included, then the lines are commented out and the two changed files are recompiled.
...> java -verify -Xverify -Xfuture verify.Main
Hello
Entered Main.foo
Exception in thread "main" java.lang.IncompatibleClassChangeError: class verify.rB does not implement interface verify.A
at verify.Main.foo(Main.java:12)
at verify.Main.main(Main.java:6)
As can be seen, the Main class loads successfully and the method foo is successfully invoked. No error is detected until the call to methodA is attempted.
The "b.methodA();" statement is compiled as an invokeinterface on verify.A.methodA, but when Main is loaded and method foo invoked the variable b cannot be widened to an A. This is easily determined by static class flow analysis, and would most certainly result in a VerifyError if classes were involved rather than interfaces. Why is the class even allowed to begin execution? -
See this JLS specification and give a code that works according to it...
5.1.5 Narrowing Reference Conversions
The following conversions are called the narrowing reference conversions:
NB: (NOT PART OF SPEC) : Rules for converting from class S to an interface K
From any class type S to any interface type K, provided that S is not final and does not implement K. (An important special case is that there is a narrowing conversion from the class type Object to any interface type.)
Give me a workable code example that illustrates this concept.
Thanks1) For every narrowing (primitive or reference)
conversions there is a corresponding widening
(primitive or reference) conversion in the
opposite direction if the code is to be run without
throwing a run time exception. Where did you get that from? For the example code given by stevejluke in reply 5, there is no corresponding widening conversion in the opposite direction (the conversion in the opposite direction is in fact another narrowing conversion, from an interface type to a non-final class type). So no, in order for the codeto run without producing an exception, there does not need to be a widening conversion in the opposite direction.
Furthermore, primitive conversions never throw any exceptions anyway.
This can be put as:
It there is a narrowing (primitive or reference)
conversion from S to T, then there should be a
widening conversion from T to S (which is taken care
at Compile Time itself). No, this in itself is not correct
This guarantees that there
will be no run time exception.
Is this a necessary and sufficient condition for the
code to run without an exception? (Or)
Is it otherwise?Now its unclear what you really want to ask. It is not true that there is always an opposite widening conversion. Perhaps you mean to ask "If there happens to be an opposite widening conversion, then will the narrowing conversoin always execute at runtime without throwing an exception?". If this is what you are asking, then the answer is no: Consider a cast from type java.lang.Object to type int[]; This cast uses a narrowing reference conversion for which there is an opposite widening reference conversion (you can look them up in chapter 5 of the JLS); However, at runtime, the Object reference might be to any instance of Object, and so might fail. E.g.:
public class Test {
public static void main(String[] argv) {
Object obj = new Object();
int[] arr = (int[])obj; // A narrowing reference conversion from type Object
// to type int[]. There is a corresponding widening
// reference conversion from int[] to Object,
// but this cast will still fail at runtime as the runtime
// type of arr is not int[]
2) Every narrowing conversion should be carried over
by an explicit cast using the cast operator, like:
S = (S) T;
No. This is true for narrowing reference conversions, but not for narrowing primitive conversions (which do not require a cast where the value is a compile-time constant small enough to be represented within the value set of the type it is being converted to). -
Final keyword and return type ...
static byte m1() {
final char c = 'b';
return c; // THIS IS FINE NO COMPILER ERROR
static byte m2() {
char c = 'b';
return c; // COMPILER ERROR
The first return type is LEGAL, but the secoond type is not because it is not final. Why is this the case? Going from a char to a byte is a down conversion. Why does the compiler allow it for a final variable and dis-allow it for the other variable?i am curious... what is this one about ?See section 5.2 of the JLS, regarding assignment conversion:
Assignment conversion occurs when the value of an expression is assigned (�15.26) to a variable: the type of the expression must be converted to the type of the variable. Assignment contexts allow the use of an identity conversion (�5.1.1), a widening primitive conversion (�5.1.2), or a widening reference conversion (�5.1.4). In addition, a narrowing primitive conversion may be used if all of the following conditions are satisfied:
The expression is a constant expression of type byte, short, char or int.
The type of the variable is byte, short, or char.
The value of the expression (which is known at compile time, because it is a constant expression) is representable in the type of the variable. -
Currency Conversion Type missing in BEx
I have created a new conversion translation type M1 based on Monthly Average exchange.
RSCUR definition for this conversion on the time ref tab to be a "variable time reference"- End of Period for
Standard Info Object Fiscal Period "0FISCPER".
Is this configuration the cause for placing a limiting restriction on the visability of this selection at runtime of query.
The following currency translation types are not available at the runtime of the query.
● Translation types for which a variable is stored (variable time reference, source currency from variable, target currency from variable, and so on).
From BEx I am unable to select Currency Conversion (Convert to Currency USD) and Use of Currency Translation M1
Thank You ...... DanAndrey:
Once BEx query results are displayed in M/S excel ... the user navigates (right click) to (local) query properties:
Tab >> Currency Conversion >> select Convert to Currency will open option to determine Currency (USD) and Currency Translation (via drill down).
Those Currency conversion types configured with variable time reference on InfoObject 0FISCPER cannot re-determine
target currency values. Fixed Time reference conversion types can be selected through BEx.
I found a restriction/ limitation in the following thread.
http://help.sap.com/saphelp_nw70/helpdata/en/ec/076f3b6c980c3be10000000a11402f/frameset.htm
Restrictions:
The following currency translation types are not available at the runtime of the query.
● Inactive translation types
● Translation types for which a variable is stored (variable time reference, source currency from variable, target currency from variable, and so on)
● Translation types in which an InfoObject is used for determining the source currency or target currency.
Are you aware of any way around this ??
Thank you ....... Dan -
Interface Conversion - Java Certification Question
Hello,
I am preparing for the Java Programmer Certification.
On page 115 of the Complete Java 2 Certification Study Guide (Simon Roberts, et al.) 2nd Edition. The author talks about object reference conversion.
OldType x = new OldType();
NewType y = x;
Where OldType could be a class, interface or array.
Question 1:
I am not clear on how OldType can be an interface. Per my understanding, you cannot create an instance of an interface.
Question 2:
The author goes on further to explain "Converting Rules". i.e for the couple of lines above to be correct, if OldType is an interface, then NewType must be Object. Why?
Thanks for your time.OldType x = new OldType();
NewType y = x;
Where OldType could be a class, interface or array.
Question 1:
I am not clear on how OldType can be an interface. Per
my understanding, you cannot create an instance of an
interface.
Question 2:
The author goes on further to explain "Converting
Rules". i.e for the couple of lines above to be
correct, if OldType is an interface, then NewType must
be Object. Why?
Thanks for your time. OldType cannot be an interface unless the code was
OldType x = new OldType() {* impl here */};
OldType could be an interface if
OldType x = new OldTypeImpl();
NewType can be an interface
Either get a better book, or transcribe the author better :) -
RoboHelp 10 Crashes consistently when trying to delete linked FM11 book
I have a linked project where RoboHelp absolutely refuses to display part of a topic and some of the images. So I decided to delete the linked FM book file and start again from scratch (this was a FM10/RH9 project originally). This causes RH to crash consistently. Any ideas?
I thought that moving my project location to a shorter path had solved my Cross references issue, but it hasn't. Here is a page from the Help:
These are all the same Heading style in FM
The X Refs are all to headings within the Current FM file
They are all the same Cross Reference Format (Heading & Page)
Thje Cross Reference conversion setting is set to Para Text in RH
Here is the code for the Graphical Circuit Trace (which doesbn't work) and the Quareo and Analyzer Configuration which does.
<li><p class="FM_Bulleted"><span class="FM_Emphasis">Graphical Circuit
Trace</span> - see <a href="Circuit_Trace_Layout.htm#XREF_67922_Graphical_Circuit"><span
class="FM_Emphasis">Graphical Circuit Trace on page 85</span></a>
for more details</p></li>
<li><p class="FM_Bulleted"><span class="FM_Emphasis">Quareo and Analyzer
Configuration</span> - <a href="Quareo_and_Analyzer_Layout.htm#XREF_15265_Quareo_and">Quareo
and Analyzer Configuration</a> for more details</p></li>
The extra span class seems to be the problem, but why is it getting applied?
Baffled.com
P.S Adobe don't seem able to replicate my problem with the PDF link, so I'm stuck there as I can't get it to work! -
Receiver file adapter not responding
Hi guys,
I have 2 interfaces in XI development system that make use of receiver file adapter in order to receive some .txt files. Although these communication channels used to work until yesterday, for some strange reason they stopped functioning, but only in development system. However, I cannot see any error in Runtime Workbench (Communication channel monitoring), it's status is "correctly configured and started" and has a green sign. But, when I sent a file from sender adapter, it is sent correctly, but it never gets received from receiver communication channel.
There is no error in SXMB_MONI either.
In XI production system, the same interfaces are functioning well.
Any ideas?
Best Regards
--EvaggelosHi Amit,
I went into Message Monitoring for this interface and I can see all the messages for the last 24 hours that should be written into a file that have status "to be delivered".
When I go into Details -->Audit Log for a single message:
2007-06-13 11:49:33 Success Processing child message of multi-message with message ID ff896d50-198a-11dc-cdfa-00145e694b16
2007-06-13 11:49:33 Success Using connection File_http://sap.com/xi/XI/System. Trying to put the message into the receive queue.
2007-06-13 11:49:33 Success Message successfully put into the queue.
And in Message Data there is the following information:
Status To Be Delivered
Repeatable Yes
Cancelable Yes
Error Category
Error Code
Start 13.06.2007 11:49:33
End
Sender Party
Sender Service TPBS_GR
Receiver Party
Receiver Service TPBS_GR
Interface http://famar.gr:LoyaltyDataMNSToSRS
MI_LoyaltyDataMNSToGR_IB
Quality of Service Exactly Once
Message b2685674-7626-5141-bfa1-13155ad0d25a
Reference
Conversation ID
Serialization Context
Direction INBOUND
Message Type Recv
Profile XI
Connection File_http://sap.com/xi/XI/System
Transport HTTP
End Point http://fmgralxi01:50000/MessagingSystem/receive/AFW/XI
Authorization
Sequential Number 0
Number of Retries 3
Failed 0
Retries 300000
Valid to
Persist Until 13.07.2007 11:49:33
Schedule Time 13.06.2007 11:49:33 -
Receiver file adapter not functioning
Hi guys,
We have developed some interfaces that are exporting some .txt files in ftp locations and therefore they make use of receiver file adapter. Although the receiver file adapter used to function properly some days ago, for some strange reason, it stopped receiving any files. This happens only in XI development system but not in XI production system. In XI development, in Runtime Workbench --> Communication Channel monitoring, I can see this communication channel's status as correctly configured and started, with a green sign on the right, but it is not responding when some files are sent to it, and therefore there are no output files in target directory.
Any ideas?? It is urgent.
Best Regards
EvaggelosUdo,
Hi Amit,
I went into Message Monitoring for this interface and I can see all the messages for the last 24 hours that should be written into a file that have status "to be delivered".
When I go into Details -->Audit Log for a single message:
2007-06-13 11:49:33 Success Processing child message of multi-message with message ID ff896d50-198a-11dc-cdfa-00145e694b16
2007-06-13 11:49:33 Success Using connection File_http://sap.com/xi/XI/System. Trying to put the message into the receive queue.
2007-06-13 11:49:33 Success Message successfully put into the queue.
And in Message Data there is the following information:
Status To Be Delivered
Repeatable Yes
Cancelable Yes
Error Category
Error Code
Start 13.06.2007 11:49:33
End
Sender Party
Sender Service TPBS_GR
Receiver Party
Receiver Service TPBS_GR
Interface http://famar.gr:LoyaltyDataMNSToSRS
MI_LoyaltyDataMNSToGR_IB
Quality of Service Exactly Once
Message b2685674-7626-5141-bfa1-13155ad0d25a
Reference
Conversation ID
Serialization Context
Direction INBOUND
Message Type Recv
Profile XI
Connection File_http://sap.com/xi/XI/System
Transport HTTP
End Point http://fmgralxi01:50000/MessagingSystem/receive/AFW/XI
Authorization
Sequential Number 0
Number of Retries 3
Failed 0
Retries 300000
Valid to
Persist Until 13.07.2007 11:49:33
Schedule Time 13.06.2007 11:49:33 -
Synchronous RFC functions from XI
Please confirm my observations.
I wanted to call a synchronously RFC Function i.e. Importing some data and Exporting some reply.
The XI message monitor shows that the RFC adapter handles this call asynchronously i.e. QOS of EO and not BE as I would have expected.
Is this behaviour I observe correct and does this then imply that there is no way of calling RFC enabled Functions on SAP expecting anything back
Thanks
AndreHi Vijaya,
Here is the message seq from the monitor for a call to a synchronous Function module :
Status Successful
Repeatable No
Cancelable No
Error Category
Error Code
Start 29.03.2006 11:51:47
End 29.03.2006 11:51:47
Sender Party
Sender Service DXI_Client_400
Receiver Party
Receiver Service DR3_Client_100
Interface
XML_Interface_With_RFC
<b>Quality of Service Exactly Once</b>
Message a2f1d6e0-bf09-11da-8b8a-000d6098578c
Reference
Conversation ID
Direction INBOUND
Message Type Recv
Profile XI
Connection AFW
Transport HTTP
End Point http://ntcdxi01:50100/MessagingSystem/receive/AFW/XI
Authorization
Sequential Number 0
Number of Retries 3
Failed 0
Retries 300000
Valid to
Persist Until 28.04.2006 11:51:47
Schedule Time 29.03.2006 11:51:47
The Audit log also shows that the call was handled asynchronously -
2006-03-29 11:51:47 Success SOAP: request message entering the adapter
2006-03-29 11:51:47 Success SOAP: completed the processing
2006-03-29 11:51:47 Success The message was successfully received by the messaging system. Profile: XI URL: http://ntcdxi01:50100/MessagingSystem/receive/AFW/XI
2006-03-29 11:51:47 Success Using connection AFW. Trying to put the message into the receive queue.
2006-03-29 11:51:47 Success Message successfully put into the queue.
2006-03-29 11:51:47 Success The message was successfully retrieved from the receive queue.
2006-03-29 11:51:47 Success The message status set to DLNG.
2006-03-29 11:51:47 Success Delivering to channel: RFC_MethodCaller
<b>2006-03-29 11:51:47 Success RFC adapter received an asynchronous message. Attempting to send tRFC for Z_THE_METHOD with TID XIel7MuBy94TgBYW0DO9XNZ0</b>
2006-03-29 11:51:47 Success The message status set to DLVD.
Any iead what I'm missing ? -
Error Category XI_J2EE_ADAPTER_XI_HANDLER
Hi
A couple of days we had problem in our Xi production server & we were unable to login into the server.
During that time the messages which got picked up from FTP went into Adapter Engine System Error.
Our Scenario is File to Idoc.
When I try to resend those messages through RWB its giving through PIAFUSER its givig wrong user id or password. Although the user id & pwd is correct.
Message Data
Attribute Value
Status System Error
Repeatable Yes
Cancelable Yes
Error Category XI_J2EE_ADAPTER_XI_HANDLER
Error Code GENERAL_ERROR
Start 12.08.2011 02:35:50
End 12.08.2011 07:08:59
Sender Party
Sender Service CLMS
Receiver Party
Receiver Service
Interface http://srl.in/clm_outbound
SRL_MI_CLM_SALES
Quality of Service Exactly Once
Message cf1c6b31-b3ed-45cb-08da-ebcbc1de3906
Reference
Conversation ID
Version 0
Edited No
Serialization Context
Direction OUTBOUND
Message Type Send
Profile XI
Connection File_http://sap.com/xi/XI/System
Transport HTTP
End Point http://srlxiprd:8000/sap/xi/engine?type=entry
Authorization SAPPasswordCredential(PIAFUSER):password=********:sapclient=900:saplang=
Sequential Number 0
Number of Retries 3
Failed 4
Retries 300000
Valid to
Persist Until 11.09.2011 02:35:50
Schedule Time 12.08.2011 06:22:55
Please give your valuable suggestion as I have lots of messages in system error.
ThanksUser XIAFUSER/PIAFUSER could have been locked.
Check the exchange profile and transaction SU01; try to reset the password.
Restart the Java Engine to activate changes in the exchange profile.
Regards
Pothana
Maybe you are looking for
-
Populate the URL for popupURL from a Table/Page Item?
Dear all, Would someone please tell me if the URL to run a BIP report can be populated from a table/page item when using popupURL and if so, how? Background: I have a Table called TBL_LETTERS with a varchar2 column REPORT_URL I have a Page (Pg 303) w
-
Document number 1700000000 has already been assigned
Dear all I create a credit memos but when I post I receive message "Document number 1700000000 in company code HDQC and fiscal year 2008 has already been assigned" I checked in IMG define number range but I don't know where to assign number range to
-
Creating two soa-infra managed servers on one Weblogic domain
I would like one weblogic domain that includes two soa-infra each pointing to its own datastore. I would like to know if this is possible? If so, can someone point me to any documentation on how to accomplish this? Thank you, David
-
Error running com.evermind.server.jms.JMSUtils
I'm running the following from the Developer prompt command window of a 10.1.2 midtier install. java -classpath C:\OraHome_AppServ\j2ee\home\oc4j.jar com.evermind.server.jms.JMSUtils destinations This gives the following error: Oracle Application Ser
-
Not deactivated licenses at computer-reset. Whom to contact?
I am using Photoshop Elements 7. One PC with license was reset without before deactivating the license and was given away. The second one was now reset, again I forgot to deactivate the license bbefore. Installing the programm was ok, but PC does no