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.

Similar Messages

  • Question about compile-time legality rules for cast conversion

    Hi, In the rules which explain compile-time legality for cast conversion, it is often mentioned the following scenario in the cast conversion of a compile-time type S to a compile-time type T:
    if S is a class type then:
    if T is a class type then either |S| <: |T| or |T| <: |S| or a compile time error occurs. Furthermore, if there exist a supertype X of T and a supertype Y of S such that X and Y are provably distinct parameterized types and that the erasures of X and Y are the same, a compile-time error occurs.
    As regards the quote in bold, I imagine the following scenario:
    1) S <: T and extends Y
    2) Y<T1...Tn>
    3) X<T1..Tn>
    4) T extends X
    Does the above represents a supertype X of T and a supertype Y of S such that X and Y are provenly distinct parameterized types? If that holds, what does it mean that the erasure of X and Y is the same?

    Declarative programing has all but gone the way of
    the doe doe because...
    1: It is not flexible (It is extremely difficult to
    change a complex system in a predetermined way)isn't this the "expert system" model?
    2: It lengthens the development cycle (see item 1)
    3: It normally forces the developer to add many
    things to there code to get things to work, that have
    nothing to do with the intent of the code.more things? the declarations or the declaration processing?
    In its defense (I like a declarative model but, do
    not like being forced into one)...not advocating a forced change in Java
    1: It increases code safety.
    2: It can shorten the development cycle, in certain
    circumstances (especially if it is not overused),
    because it can greatly increase the readability of
    code.
    3: It follows many best practices (although this is
    also possible in a Non-Declarative model).as for best practices what I'd like to see are declarative design patterns, Adapter, Singleton, Factory, Delegate, Strategy, Interpreter, Proxy, Visitor
    too often the design intent is lost in an implementation or design details can only be deduced by class/field/method names, comments, and accompanying docs
    So, if everyone had unlimited time, and an unlimited
    budget, yes declaritive is the way to go. Since that
    is not the case, we filtered out 99% of what it gave
    us, made sure the stuff that was getting in the way
    was removed, and what do you have???
    You guessed it OOA&D.
    Now having said that should we be more declarative? I
    think so, but I will tell you now, REQUIRING
    declarative elements in code is a sure fire way to
    get the majority of development groups to drop the
    language (and I think Java as it stands currently CAN
    be declarative, so if you have one of those unlimited
    budgets, go for it!).no need to require it
    I believe given good (reusable) declarative options, on top of OOP, will become the chosen approach
    reusable design declarations would lessen overall cost and increase readability

  • Cast from Class A to Class A B should be allowed?

    https://bugs.eclipse.org/bugs/show_bug.cgi?id=99107
    public final class A<B> {
      void doit() {
        Class<A> clazz1 = (Class<A>) this.getClass();
        Class<A<B>> clazz2 = (Class<A<B>>) clazz1;
        clazz2.getName();
    }Sun's javac (1.5.0_03) gives an error:
    A.java:5: inconvertible types
    found   : java.lang.Class<A>
    required: java.lang.Class<A<B>>
        Class<A<B>> clazz2 = (Class<A<B>>) clazz1;
                                           ^------- Additional Comment #1 From Philippe Mulet 2005-06-09 06:11 [reply] -------
    According to the spec, cast conversion is allowed since the types are not
    probably distinct.
    I thus believe this is a bug in javac.

    You can get around this with a double cast.
    Class<A<B>> clazz2 = (Class<A<B>>) (Class) clazz1
    Ugly, but it compiles. :(Or simply:
    Class<A<B>> clazz2 = (Class) clazz1However, I suspect that the OP wasn't really looking
    for a work around ;-) I have noted the problem and
    will file a javac bug if it isn't a dupe.

  • Arbitrary casting between interfaces is allowed?

    hi,
    i'm confused since i thought you could not do this
    interface ITreePlanter {
         public void plantTree();
    interface IMotorCycleRepairer {
         public void repairMotorCycle();
    class foo {
         void bar() {
              ITreePlanter a = null;
              IMotorCycleRepairer b = (IMotorCycleRepairer) a;
              a = (ITreePlanter) b;
    }but apparently you can!
    changing the interfaces to abstract classes, or classes produces compilation errors. Anyone have any insights into why this is?
    thanks,
    asjf

    JLS, 2nd ed, 5.5: The remaining cases involve conversion between reference types. The detailed rules
    for compile-time correctness checking of a casting conversion of a value of compile-time
    reference type S (source) to a compile-time reference type T (target) are as follows:
        * If S is a class type:
              o If T is a class type, then S and T must be related classes-that is, S and T must
                be the same class, or S a subclass of T, or T a subclass of S; otherwise a
                compile-time error occurs.
              o If T is an interface type:
                    + If S is not a final class (�8.1.1), then the cast is always correct at compile
                      time (because even if S does not implement T, a subclass of S might).
                    + If S is a final class (�8.1.1), then S must implement T, or a compile-time
                      error occurs.
              o If T is an array type, then S must be the class Object, or a compile-time error
                occurs.
        * If S is an interface type:
              o If T is an array type, then T must implement S, or a compile-time error occurs.
              o If T is a class type that is not final (�8.1.1), then the cast is always correct at
                compile time (because even if T does not implement S, a subclass of T might).
              o If T is an interface type and if T and S contain methods with the same signature
                (�8.4.2) but different return types, then a compile-time error occurs.
        * If S is an array type SC[], that is, an array of components of type SC:
              o If T is a class type, then if T is not Object, then a compile-time error occurs
                (because Object is the only class type to which arrays can be assigned).
              o If T is an interface type, then a compile-time error occurs unless T is the type
                java.io.Serializable or the type Cloneable, the only interfaces implemented by
                arrays.
              o If T is an array type TC[], that is, an array of components of type TC, then a
                compile-time error occurs unless one of the following is true:
                    + TC and SC are the same primitive type.
                    + TC and SC are reference types and type SC can be cast to TC by a
                      recursive application of these compile-time rules for casting. Your situation is that S and T are both interface types, so a compile-time error occurs only if T and S contain methods with the same signature but different return types.

  • Create Invoice From a Draft

    Hi everybody,
                        I'm trying to create an invoice from an existing draft by code and i can't...i use this code to do this, but it create a new draft instead an invoice.
    oCompany.XmlExportType = SAPbobsCOM.BoXmlExportTypes.xet_ExportImportMode
    oCompany.XMLAsString = False
    oDrafts = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oDrafts)
    oFacts = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oInvoices)
    oDrafts.GetByKey(20)
    oDrafts.SaveXML("C:\draft.xml")
    oFacts = oCompany.GetBusinessObjectFromXML("C:\draft.xml",0)
    oFacts.DocObjectCode = SAPbobsCOM.BoObjectTypes.oInvoices
    oFacts.Add()

    Hi Mariano Bertini,
    Can you pls share the code as i'm facing the same problem for conversion of open draft a/r invoice to invoice

  • An array and scalar values together in an sql statement

    Hi
    We have a table called SERVICE and following are the 3 columns from SERVICE table,
    SERVICESTATUSID - NUMBER(10)
    ACCOUNTID - NUMBER(10)
    SERVICENUMBER - VARCHAR(41)
    My aim is to be able to update the status of a bunch of entries in this table from Pro C code with new ServiceStatusID where accountId matches the accountId supplied and SERVICENUMBER exists in the list of services supplied.
    Now I am trying to use host arrays here for SERVICENUMBERs and then my Update statement looks like this,
    UPDATE SERVICE SET SERVICESTATUSID = :x WHERE ACCOUNTID = :y AND SERVICENUMBER = :z
    And then I am trying to execute it with the help of bind variables in Pro C as follows,
    EXEC SQL AT DB_NAME CONTEXT USE :myContext;
    EXEC SQL AT DB_NAME DECLARE sqlStatement STATEMENT;
    EXEC SQL AT DB_NAME PREPARE sqlStatement FROM :str;
    EXEC SQL AT DB_NAME EXECUTE sqlStatement USING :statusId, :accountId, :serviceNumbersList;
    where statusId is integer,

    user12169137 wrote:
    Now I am trying to use host arrays here for SERVICENUMBERs and then my Update statement looks like this,
    UPDATE SERVICE SET SERVICESTATUSID = :x WHERE ACCOUNTID = :y AND SERVICENUMBER = :z
    And then I am trying to execute it with the help of bind variables in Pro C as follows,
    EXEC SQL AT DB_NAME CONTEXT USE :myContext;
    EXEC SQL AT DB_NAME DECLARE sqlStatement STATEMENT;
    EXEC SQL AT DB_NAME PREPARE sqlStatement FROM :str;
    EXEC SQL AT DB_NAME EXECUTE sqlStatement USING :statusId, :accountId, :serviceNumbersList;
    where statusId is integer,I am not sure what you are asking. I think you want statusId to be a scalar integer but use a series of values for the service numbers.
    This can be done, but will take a little effort. It might be most easily done in a PL/SQL block where you can control the datatypes too. What you will have to do is create a database object with the datatype (integer, number, whatever), then another object as a table of that object. It should then be possible to convert your collection into a database nested table with the CAST() function. Don't expect really good performance from this.
    Search OTN for cast conversions for more information on this method.
    Another alternative if you have < 1000 items is to use dynamic SQL by generating an IN list from your collection contents. Again, performance will probably not be great.
    Good luck.

  • JavaFX's null not allowed is a thorn in my side....

    Hi All,
    Rule: JavaFX's data types (i.e. Number, Double, String, Integer) can't be null.
    My JavaFX Application listen's for real time data updates. Since this is a listener, it won't have a value til it get's the first update. Sounds fair enough... but they can't be null! So, I must use java.lang.Double instead. But all binding's convert the java.lang.Double null value to a javafx Double value of 0.0. So now I have broken logic in my program as 0.0 is a legitimate value and certainly does not signify 'null'. So, then it looks like I am stuck entirely with java.lang.Double everywhere! But then I'd need to do my own java.lang.Double -> fx.Double casting class/function to handle the cast conversion of each binding in order to interact sensibly with the JavaFX API (as it like's the FX Double everywhere and won't throw a nullpointer exception when casting).
    Rule: JavaFX's sequences can't contain null entries.
    Further more, I could say "Nope, I don't have a value/update yet so I will just use an object placeholder/wrapper with null assignment". In my case, JavaFX object's are multiple and ordered. Perfect for a sequence! Except, you can't store null in a sequence! Thus, if you are looking for a team's sport's top batsman.. the 3rd batsman and they don't exist yet.. then 'team[2] = null' wont insert! So how can I find and bind to the 3rd batsman? We'll either I avoid sequences, which means native array's or java collections... but then I can't really bind to them! Or, everytime the sequence changes I need to search/iterate over the entire sequence to determine if there is a 3rd batsman in the sequence (and that won't necessarily be the 3rd entry).
    Both these 'null not allowed' rules cause significant problems and have huge flow on effects onto the code that uses them. I believe this is totally wrong and a bad feature of the language and completely contradicts autoboxing! The identification of a data type reference being null is extremely significant. It is the responsibility of the receiver of a null reference/argument to decided how they want to handle the null reference (see autoboxing nullpointer exceptions if you don't believe me and reasons not to use java primitives). Removing the ability for this to occur is a step backwards for functional programming. I know you will say that I could just use the java.lang.*, a fair claim... but don't forget this means more work! The very reason you might be considering JavaFX in the first place.
    Anyway my rant is over, I really love JavaFX.... just not these x2 rules.

    The technique PhiLho refers to is often called the "null object pattern". If done properly it needn't be hackish at all, and indeed it can simplify a lot of processing code. Even if the "primitive" values (Number, String, etc.) could be null, and even if you could put nulls into a sequence, you're probably better off putting in an actual object that represents the absence of a value. The reason is that when you go to process that data, instead of just processing it, you have to put in checks for nulls here and there, and do special-case processing for it.
    Consider displaying a list of, say, the top five batsmen. You'll want to have a sequence of five batsmen, and you'll want to put five CustomNodes or something into a VBox to display the names, statistics, etc., something like the following:
    VBox {
        content: [
            for (b in [0..<5]) {
                BatsmanNode {
                    name: bind batsmen.name
    innings: bind batsmen[i].innings
    notOuts: bind batsmen[i].notOuts
    visible: bind batsmen[i].valid
    You can't do this if there were a null in the sequence, even if it were allowed. Instead, you should put a "fake" batsman object into the sequence, and make its "valid" variable be false. This way the corresponding BatsmanNode will be invisible. Or, you could have it display "(no entry)" in grey text, or something like that.
    The point is that if you always have a real object there, even if it represents a "null" or the absence of a value, it removes special-case processing code and enables you to do things like bind to it.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Object Inheritance problem between projects

    Hi,
    I have two projects lets say project1 and project2. From project1 I instanciate processes of project2 as subflows. In addition I have one bpm object in project1 (lets say object1) that inherits from a bpm object in proyect2 (lets say object2). So project1 depends on project2 to make this inheritance happen. When I call the subflow I pass the object1 and as inherits from object2 there is no problem (input argument). For the output argument I have to cast from object2 to object1. And here is where I have a classcastexception. If all the processes are in the same project it works fine and there is no exception. But when splitting in two projects it fails. Seems that it is something related to the folder structure in the catalog that should be the same for both projects and that is the reason why it does not work, but as one project depends to the other I can not put the same folder structure in both catalogs because in the dependant project it is duplicated.
    Has anybody can give me an idea on how to solve this?
    Thank you very much in advance
    Kind regards

    Nobody can help me with this issue?,any help is much appreciated, the excpetion I get is:
    An operation exception occurred while running an automatic item. Details: An instance in Process '/Prueba#Default-1.0' could not be notified. Caused by: Process execution engine execution error. Caused by: The method 'CIL_otherProjectOtherProjectIn' from class 'Novartis.Prueba.Default_1_0.Instance' could not be successfully executed. Caused by: Cannot convert an object with type xobject.BaseModule.BaseObject to class xobject.DependantModule.DependantObject fuego.papi.exception.CannotStoreNotificationException: An instance in Process '/Prueba#Default-1.0' could not be notified. at fuego.server.AbstractProcessBean.receiveNotification(AbstractProcessBean.java:2791) at fuego.server.iec.LocalIPCHandler.sendNotification(LocalIPCHandler.java:79) at fuego.server.execution.microactivity.DefaultSendNotificationExecutionHandler.sendNotification(DefaultSendNotificationExecutionHandler.java:103) at fuego.server.execution.microactivity.EndMicroActivity.execute(EndMicroActivity.java:69) at fuego.server.execution.microactivity.MicroActivityEngineExecutionHandler.executeActivity(MicroActivityEngineExecutionHandler.java:57) at fuego.server.execution.ImmediateActivity.execute(ImmediateActivity.java:42) at fuego.server.execution.DefaultEngineExecution$AtomicExecutionTA.runTransaction(DefaultEngineExecution.java:304) at fuego.transaction.TransactionAction.startBaseTransaction(TransactionAction.java:470) at fuego.transaction.TransactionAction.startTransaction(TransactionAction.java:551) at fuego.transaction.TransactionAction.start(TransactionAction.java:212) at fuego.server.execution.DefaultEngineExecution.executeImmediate(DefaultEngineExecution.java:123) at fuego.server.execution.DefaultEngineExecution.executeAutomaticWork(DefaultEngineExecution.java:62) at fuego.server.execution.EngineExecution.executeAutomaticWork(EngineExecution.java:42) at fuego.server.execution.ToDoItem.executeAutomaticWork(ToDoItem.java:251) at fuego.server.execution.ToDoItem.run(ToDoItem.java:536) at fuego.component.ExecutionThread.processMessage(ExecutionThread.java:775) at fuego.component.ExecutionThread.processBatch(ExecutionThread.java:755) at fuego.component.ExecutionThread.doProcessBatch(ExecutionThread.java:142) at fuego.component.ExecutionThread.doProcessBatch(ExecutionThread.java:134) at fuego.fengine.ToDoQueueThread$PrincipalWrapper.processBatch(ToDoQueueThread.java:450) at fuego.component.ExecutionThread.work(ExecutionThread.java:839) at fuego.component.ExecutionThread.run(ExecutionThread.java:408) Caused by: fuego.papi.impl.EngineExecutionException: Process execution engine execution error. at fuego.server.execution.DefaultEngineExecution.executeWithoutComponentImmediate(DefaultEngineExecution.java:202) at fuego.server.execution.EngineExecution.executeWithoutComponentImmediate(EngineExecution.java:95) at fuego.server.AbstractProcessBean.receiveNotification(AbstractProcessBean.java:2757) ... 21 more Caused by: fuego.lang.ComponentExecutionException: The method 'CIL_otherProjectOtherProjectIn' from class 'Novartis.Prueba.Default_1_0.Instance' could not be successfully executed. at fuego.component.ExecutionThreadContext.invokeMethod(ExecutionThreadContext.java:519) at fuego.component.ExecutionThreadContext.invokeMethod(ExecutionThreadContext.java:273) at fuego.fengine.FEEngineExecutionContext.invokeMethodAsCil(FEEngineExecutionContext.java:219) at fuego.server.execution.EngineExecutionContext.runCil(EngineExecutionContext.java:1277) at fuego.server.execution.microactivity.ComponentExecutionMicroActivity.runCil(ComponentExecutionMicroActivity.java:126) at fuego.server.execution.microactivity.ComponentExecutionMicroActivity.execute(ComponentExecutionMicroActivity.java:84) at fuego.server.execution.microactivity.MicroActivityEngineExecutionHandler.executeActivity(MicroActivityEngineExecutionHandler.java:57) at fuego.server.execution.ImmediateActivity.execute(ImmediateActivity.java:42) at fuego.server.execution.DefaultEngineExecution$AtomicExecutionTA.runTransaction(DefaultEngineExecution.java:304) at fuego.transaction.TransactionAction.startNestedTransaction(TransactionAction.java:527) at fuego.transaction.TransactionAction.startTransaction(TransactionAction.java:548) at fuego.transaction.TransactionAction.start(TransactionAction.java:212) at fuego.server.execution.DefaultEngineExecution.executeImmediate(DefaultEngineExecution.java:123) at fuego.server.execution.DefaultEngineExecution.executeWithoutComponentImmediate(DefaultEngineExecution.java:199) ... 23 more Caused by: java.lang.ClassCastException: Cannot convert an object with type xobject.BaseModule.BaseObject to class xobject.DependantModule.DependantObject at fuego.util.Conversion.cast(Conversion.java:99) at Novartis.Prueba.Default_1_0.Instance.CIL_otherProjectOtherProjectIn(Instance.xcdl:1) at Novartis.Prueba.Default_1_0.Instance.CIL_otherProjectOtherProjectIn(Instance.xcdl) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at fuego.component.ExecutionThreadContext.invokeMethod(ExecutionThreadContext.java:512) ... 36 more
    The strange thing is that if all the processes are in the same project everything works fine but once I split in two projects it raises the exception.
    Thank you very much

  • Convert Mainframe Packed Decimal to Oralce Number Format

    Dear all,
    I am having a file in which amount fields are given in a Packed Decimal format. Can anyone suggest me how I can read this data element from the file and convert it into Oracle Number datatype.
    File is a fixed length. All the amount fields are given in Packed Decimal Format and rest of the fields are given in text format.
    Thanks and regards
    Nagasayan Puppala

    Hi,
    Firstly thanks for your reply.
    Actually I am not using SQL Loader to load data from
    a flat file to Oracle table. I am writing a custom
    program that reads the file and populates the oracle
    table. I'll put aside the question of 'why' you'd want to do that. SQL*Loader's singular purpose in life is to load flat files of data into Oracle DB. Sometimes there is a reason for reinventing the wheel.
    How does your program communicate with the Oracle DB? If utilizing ESQL and Pro*Cobol (or Pro*<whatever> ) you will have read the data into a variable of some type in you host language. The variable of the host variable to hold the value (if you did a 'select from' that table) would be the correct target type for an insert statement. Whatever host language type conversion is available bewteen those two types ( if they are different at all ) is all that is needed. The precompilers have converters between certain native host and internal Oracle types built-in. It is how you get any data between the two systems. This is only a problem if the host language has no converter between the numeric types (if differnet.). When you read from the flat file are you reading it into a native packed decimal in the host language?
    ODBC/JDBC similar strategy..... cast conversion between the native type that Oracle wants and the one into which your custom program reads it into.
    So I want to know whether there are any Oracle
    utility programs that will convert the packed decimal
    to a oracle number format or not.There are Oracle routines that convert into the native Oracle DB formats. There are implicitly available through the normally utilized interfaces to OCI ( ESQL and ODBC/JDBC ) . There are none decoupled from those interfaces though (that I know of).
    There are no standalone programs that mutate a flat file into another flat file that then could be loaded. That's is typically slower and utilzes more space than most customers want than just directly inputing the data into Oracle DB.
    Message was edited by:
    lytaylor

  • RULE BASED OPTIMIZER

    hi,
    my database is 10.2.0.1...by default optimizer_mode=ALL_ROWS..
    for some sessions..i need rule based optimizer...
    so can i use
    alter session set optimizer_mode=rule;
    will it effect that session only or entire database....
    and following also.i want to make them at session level...
    ALTER SESSION SET "_HASH_JOIN_ENABLED" = FALSE;
    ALTER SESSION SET "_OPTIMIZER_SORTMERGE_JOIN_ENABLED" = FALSE ;
    ALTER SESSION SET "_OPTIMIZER_JOIN_SEL_SANITY_CHECK" = TRUE;
    will those effect only session or entire database...please suggest

    < CBO outperforms RBO ALWAYS! > I disagree - mildlyWhen I tune SQL, the first thing I try is a RULE hint, and in very simple databases, the RBO still does a good job.
    Of course, you should not use RULE hints in production (That's Oracle job).
    When Oracle eBusiness suite migrated to the CBO, they placed gobs of RULE hints into their own SQL!!
    Anyway, always adjust your CBO stats to replicate an RBO execution plan . . . .
    specifically CAST() conversions from collections and pipelined functions.Interesting. Hsve you tried dynamic sampling for that?
    Hope this helps. . .
    Don Burleson
    Oracle Press author
    Author of “Oracle Tuning: The Definitive Reference”
    http://www.dba-oracle.com/bp/s_oracle_tuning_book.htm

  • Reference equality for X and Integer

    Hi,
    my problem is that i'd like to understand why java won't accept this statement at compile time.
    Class X { .... }
    Class Y {
       doSomething(...) {
          X x1;
          Integer i;
          boolean b = i == x1;
    }I absolutly know that this code makes no sense but I don't understand my java won't compile this type of code. The problem is the comparsion of Integer and X but they are both objects so why doesn't it word?
    If I use another variable with the type of Y the comparsion would be executed at runtime.
    Thanks a lot
    Jonny

    You are trying to compare references of types that are incompatible.
    Here is the relevant part of the Java Spec on == (Section 15.21.3):
    "A compile-time error occurs if it is impossible to convert the type of either operand to the type of the other by a casting conversion (5.5). The run-time values of the two operands would necessarily be unequal."
    Some other commenter recommended using equals, which of course, will never return true in this case and probably throw a runtime exception anyways.
    They might want to re-read my comments in the Topic Java app disobeying 'if' structure abort the importance to understand the difference between == and Object.equals.

  • Compare contrast 2 recordsets?

    Ok, I have one procedure that has two record set in it. The way that it looks is sort of like this.
    create or replace
    PROCEDURE PROC2RECS AS
    BEGIN   
    FOR rec IN (  SELECT some, information, FROM DB1 dblink to another db.
       LOOP    
            IF (condition etc...)       
            ELSIF (condition etc...)          
                 -- UPDATE something
                 -- SET something = someother thing;         
            ELSIF (condition etc...)
            END IF;      
       END LOOP;  
    FOR rec2 IN (  SELECT some, information, FROM LocalDB
       LOOP    
            IF (condition etc...)       
            ELSIF (condition etc...)          
                 -- UPDATE something
                 -- SET something = someother thing;         
            ELSIF (condition etc...)
            END IF;      
       END LOOP;     
    END PROC2RECS;Now these recordsets are coming from two different Oracle 8i databases is there a way to combine thes recordsets to get data from them?
    In other words. Like do a
    IF rec.id <>  rec2.id THEN
          output something;
    END IF

    You're limited in your options by still being on 8i. I'm not sure CAST() conversions against database types will work there, and the 10g set operations (which I've only gotten to work on simple one-element collections besides) won't work either.
    One option is to load the data into tables (do global temporary tables exist in 8i?) and perform set operations on them.

  • Filter Data based on date Condition

    Hi,
    Below is the query which is performing cast operation to convert string to date. Now my requirement is to filter all the dates which is from 1/1/2010 or later.
    >> SELECT
    >> CAST( TICKETID AS VARCHAR2(4000)) TICKETID,
    CAST(CUSTOMERID AS VARCHAR2(4000)) CUSTOMERID,
    CAST(CUSTOMEREMAIL AS VARCHAR2(4000)) CUSTOMEREMAIL,
    CAST(CREATEDBY AS VARCHAR2(4000)) CREATEDBY,
    TO_CHAR (TO_DATE ( CAST (DATECREATED AS VARCHAR2 (4000)) , 'Mon DD YYYY HH:MIAM'),'DD-MM-YYYY HH24:MI:SS') DATECREATED
    FROM TICKETSI tried with the below format, But it shows as not a valid month to filter please suggest me how to perform the filter on this cast operation of cast conversion.
    >> SELECT * FROM
    >> ( SELECT
    CAST( TICKETID AS VARCHAR2(4000)) TICKETID,
    CAST(CUSTOMERID AS VARCHAR2(4000)) CUSTOMERID,
    CAST(CUSTOMEREMAIL AS VARCHAR2(4000)) CUSTOMEREMAIL,
    CAST(CREATEDBY AS VARCHAR2(4000)) CREATEDBY,
    TO_CHAR (TO_DATE ( CAST (DATECREATED AS VARCHAR2 (4000)) , 'Mon DD YYYY HH:MIAM'),'DD-MM-YYYY HH24:MI:SS') DATECREATED
    FROM TICKETS )
    WHERE
    DATECREATED >= TO_DATE('01-01-2010','DD-MM-YYYY HH24:MI:SS') Please suggest me how to put a filter on this date.
    Thanks
    Sudhir

    Sudhir_Meru wrote:
    SELECT * FROM
    ( SELECT
    CAST( TICKETID AS VARCHAR2(4000)) TICKETID,
    CAST(CUSTOMERID AS VARCHAR2(4000)) CUSTOMERID,
    CAST(CUSTOMEREMAIL AS VARCHAR2(4000)) CUSTOMEREMAIL,
    CAST(CREATEDBY AS VARCHAR2(4000)) CREATEDBY,
    TO_CHAR (TO_DATE ( CAST (DATECREATED AS VARCHAR2 (4000)) , 'Mon DD YYYY HH:MIAM'),'DD-MM-YYYY HH24:MI:SS') DATECREATED
    FROM TICKETS )
    WHERE
    DATECREATED >= TO_DATE('01-01-2010','DD-MM-YYYY HH24:MI:SS')
    Plainly un-necessary CHAR-DATE-CHAR conversion and CHAR - Date comparison.
    Why do you need it?
    Just use
    TO_DATE ( CAST (DATECREATED AS VARCHAR2 (4000)) , 'Mon DD YYYY HH:MIAM')          DATECREATEDAnd then you can do
    datecreated >= to_date('01-01-2010 00:00:00', 'DD-MM-YYYY HH24:MI:SS')

  • Typecast Variables Changing Types Dynamically

    OK... this is a relatively simple app that is database driven... the problem comes in when didSelectRowAtIndexPath executes... here is the code:
    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    NSUInteger row = [indexPath row];
    MyAppDelegete *appDelegate = (MyAppDelegate *)[[UIApplication sharedApplication] delegate];
    MyController *myvariable = [[MyController alloc] init];
    myvariable = (MyController *)[appDelegate.myArray objectAtIndex:row];
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    [defaults setObject:myvariable.myArrayMember forKey:kConstantValue];
    [myvariable release];
    What's happening is that when "myvariable" is cast to be a pointer to MyController, is is set correctly, and the type of the variable reflects correctly in the debugger. When the next line is executed, however, where the array is index by the row selected, and the results are assigned to myvariable, the TYPE of myvariable CHANGES from (MyController *) to (UICGColor *).
    I've checked to make sure that the array is declared correctly (the debugger says that after being loaded from the database, there are 39 objects in it), and that it is not being released too early (it is released in the MyAppDelegate's Dealloc method).
    Does anyone have any ideas why this may be getting re-cast?
    Message was edited by: Incognitii Formatting is all screwed up here... don't know why.

    Hi Incognitii , and welcome to the Dev. Forum!
    There are at least two bad things going on here, based on the code you posted and your description of an unexpected object type. Instead of focusing immediately on fixing the code, I think I can help you much more by clearing up some misunderstandings.
    1) A type cast doesn't change the type of an object. The cast merely turns off the compiler's type checking. Here's an example:
    UILabel *label = (UILabel*)[[UIViewController alloc] init];
    Without the cast, the compiler will yell at you: "Hey!! You just stored the address of a new controller object in a variable intended for the address of a label! That's an accident waiting to happen, Dude. Don't do it!!".
    With the cast, the compiler keeps it's mouth shut. In effect you're saying, "I know this looks kinky to you, but remember you're just a machine and I'm the programmer. I know what I'm doing, so zip it up or I'll trade you in for Visual Studio!".
    But either way, a UIViewController object was made on the right side of the above statement, and a pointer to that object has been stored in the 'label' var. So we can pretend the object is a label if it makes us happy, but it's still a view controller.
    Type casts are to be avoided whenever possible. Don't put any type casts into the first draft of your code. Then, if you get a Type Mismatch warning from the compiler, think long and hard about telling the compiler to shut up. Sometimes the type cast will be the correct decision, but more ofter than not, when you're first learning Cocoa, the compiler is right and you need to fix your code.
    2) Here's a common error that comes up when we forget that an object pointer variable just stores an address that can be replaced by another address any time we put the var on the left side of an assignment statement:
    Citizenship *citizenNew = [[Citizenship alloc] init]; // Line 1 - store addy of new object
    citizenNew = (Citizenship *)
    [appDelegate.citizenship objectAtIndex:row]; // Line 2 - replace that addy
    [citizenNew release]; // Line 3 - release object in array
    + In line 1 a new object of type Citizenship is made and its address is stored in citizenNew. So far so good.
    + In Line 2, the address of a second object is obtained from the citizenship array and stored in citizenNew. The address of the second object has thus replaced the address of the new object. The address of the new object is no longer stored anywhere so that object can never be released.
    + In Line 3, the object whose address is stored in citizenNew is released. The address in citizenNew points to the object at index row in the array, so that object is released.
    3) Note that NSArray objects save pointers of type 'id'. This means the array doesn't know or care what type of object is being referenced by each pointer. It's up to the programmer to know what types of object pointers are stored in the array, or dynamically classify the objects if necessary.
    I've checked to make sure that the array is declared correctly.
    This doesn't tell us anything about what types of object pointers have been stored in the array. Going back to point no. 1, a misunderstanding about the power of a type cast may have given you a false sense of security. If the array was loaded from a data base, consider the possibility that there could be most anything in it.
    One way to get a handle on what's in an array is to use NSLog(). Some semi-permanent logging can alert you to side effects after your attention has moved on to some other module:
    // put this somewhere that only runs once after any change to
    // the array; if the array wants to be too big for logging, it might
    // not hurt to keep it small until you know what's going on.
    NSLog(@"citizenship=%@", appDelegate.citizenship);
    // then in the code block:
    citizenNew = [appDelegate.citizenship objectAtIndex:row]; // cast shouldn't be needed here, btw
    NSLog(@"row=%d citizenNew=%@", row, citizenNew);
    I hope the above gives you the tools to sort things out!
    - Ray
    p.s.: To format your code see the yellow alert post that's first on the topic page:
    Paste your code here.

  • Insert floats fail...

    Hi!
    I create a table like:
    create table tab(column1 number(8,2));
    When I intended to insert values with:
    insert into tab values (3.2);
    However, I have a error:
    OCA-30021: error preparing/executing SQL statement
    [POL-2404] invalid characters specified for cast conversion
    This is on SQL*Plus in Windows 98 Second Edition.
    How can I insert this values?
    Would somebody helpme?
    Thanks in advance.

    A-ha!
    I suspect (as Joachim does) that you have a character set problem:
    For example, in the UK and US "3,5" means "three,five", whereas mainland Europeans would read "three and a half".
    null

Maybe you are looking for