Compile time constants

Hey i have a doubt regd compile time constants
byte a =10,b=20;
byte c= a+b; // compile time error coz a+b may exceed byte limit
int a=10,b=20;
int d=a+b; // not showing any error . a+b may exceed int limit
can anyone clear me int his

public class Test {
    public static void main(String[] args) {
        byte a = 10, b = 20;
        byte c = a+b;  //syntax error: "possible loss of precision"
        final byte d = 10, e = 20;
        byte f = d+e;  //OK
}It's not about overflow, but implicit casting: in the expression a+b, bytes a and b
are widened to int and the addition is 32-bit addition -- the result is an int.
When you attempt to assign an int to a byte, the top three bytes are discarded,
hence the syntax error "possible loss of precision". You get the same
error message when assigning a double to a float.
Why don't I get the syntax error with my d-e-f example? Variables d and e
are declared final, so the compiler folds in their values. Thus it know 10+20
is 30 and that the int value 30 fits into one byte.

Similar Messages

  • Error 1046: Type was not found or was not a compile-time constant: Component Event.

    Hi Everyone..
    I am getting an Error 1046: Type was not found or was not a compile-time constant: Component Event.
    The ComponentEvent class has been imported,and also the event handling code is there. I am not sure what else is wrong, hope somebody can advise me. Thanks. The code is below, the point where the error occurs as indicated by the compiler has been highlighted.
    package 
    import flash.display.Sprite;
    import flash.media.Camera;
    import flash.media.Microphone;
    import flash.media.Video;
    import fl.controls.TextArea;
    import fl.controls.Button;
    import fl.controls.TextInput;
    import flash.events.SyncEvent;
    import flash.events.MouseEvent;
    import flash.events.FocusEvent;
    import flash.net.SharedObject;
    import flash.net.NetConnection;
    import flash.net.NetStream;
    import flash.events.NetStatusEvent;
    import flash.events.FocusEvent;
    import flash.events.ComponentEvent;
    public class VideoChat extends Sprite
      private var button:Button;
      private var text_so:SharedObject; 
      private var textArea:TextArea;
      private var textInput:TextInput;
      private var chatName:TextInput; 
      private var nc:NetConnection;
      private var nsOut:NetStream;
      private var nsIn:NetStream;
      private var rtmpNow:String;
      private var msg:Boolean; 
      private var cam:Camera;
      private var mic:Microphone;
      private var vid:Video;
      public function VideoChat ()
       //Set up UI
       textArea = new TextArea();
       textArea.setSize(500,280);
       textArea.move(20,54);
       addChild(textArea);
       textInput = new TextInput();
       textInput.setSize(500,24);
       textInput.move(20,340);
       textInput.addEventListener(ComponentEvent.ENTER,checkKey);
       addChild(textInput);
       button = new Button();
       button.width=50;
       button.label="Send";
       button.move(20,370);
       button.addEventListener(MouseEvent.CLICK, sendMsg);
       addChild(button);
       chatName = new TextInput;
       chatName.setSize (100,24);
       chatName.move (80,370);
       chatName.text="<Enter Name>";
       chatName.addEventListener (FocusEvent.FOCUS_IN, cleanName);
       addChild(chatName); 
       //Connect
       rtmpNow="rtmp:/VideoChat ";  
       nc=new NetConnection;
       nc.connect (rtmpNow);
       nc.addEventListener(NetStatusEvent.NET_STATUS,doSO);
       cam = Camera.getCamera();
       mic=Microphone.getMicrophone();
       //Camera Settings
       cam.setKeyFrameInterval(15);
       cam.setMode (240, 180, 15, false);
       cam.setMotionLevel(35,3000);
       cam.setQuality(40000 / 8,0);
       //Microphone Settings
       mic.gain = 85;
       mic.rate=11;
       mic.setSilenceLevel (25,1000);
       mic.setUseEchoSuppression (true);
       //Video Setup
       vid=new Video(cam.width, cam.height);
       addChild (vid);
       vid.x=10, vid.y=20;  
       //Attach local video and camera
       vid.attachCamera(cam);  
      private function doSO(e:NetStatusEvent):void
       good=e.info.code == "NetConnection.Connect.Success";
       if(good)
        //Set up shared object
        text_so=SharedObject.getRemote("test", nc.uri, false);
        text_so.connect (nc);
        text_so.addEventListener(SyncEvent.SYNC, checkSO);
      private function checkSO(e:SyncEvent):void
       for (var chung:uint; change<e.changeList.length; chng++)
        switch(e.chageList[chng].code)
         case "clear":
          break;
         case "success":
          break;
         case "change":
          textArea.appendText (text_so.data.msg + "\n");
          break;
      private function cleanName(e:FocusEvent): void
       chatName.text="";
      private function sendMsg(e:MouseEvent):void
       noName=(chatName.text=="<Enter Name>" || chatName.text=="");
       if (noName)
         textArea.appendText("You must enter your name \n");
       else
        text_so.setProperty("msg", chatName.text +": " + textInput.text);
        textArea.appendText (chatName.text +": "+textInput.text +"\n");
        textInput.text="";
      private function checkKey (e:ComponentEvent):void
       noName=(chatName.text=="<Enter Name>" || chatName.text=="");
       if (noName)
         textArea.appendText("You must enter your name \n");
       else
        text_so.setProperty("msg", chatName.text +": " + textInput.text);
        textArea.appendText (chatName.text +": "+textInput.text +"\n");
        textInput.text="";
      //Create NetStream instances
      private function checkConnect  (e:NetStatusEvent):void
       msg=e.info.code == "NetConnection.Connect.Success";
       if(msg)
        nsOut=new NetStream(nc);
        nsIn=new NetStream(nc);
        //NetStream
        nsOut.attachAudio(mic);
        nsOut.attachCamera(cam);
        nsOut.publish("camstream");
        nsIn.play("camstream");

    Hi Guys...
    I have found out what is wrong. I was importing the wrong package the correct one should have been:
    import fl.events.ComponentEvent;
    instead of
    import flash.events.ComponentEvent;
    I hope this is helpful for anyone caught in a simillar situation as me...Thanks..

  • Constants v/s compile time constants.

    Hi to all.
    I got a problem in understanding compile time constants.
    I was reading about switch statement, and found a fact:
    the case constant in switch statement should be compile time constant.
    and example they have given is:
    final int a=1;
    final int b;
    b=2;
    int x=0;
    switch(x)
    case a: //ok.
    case b: //compiler error.
    so is it true, that compile time constants are only those which are final and are initialized at the time of declaration itself.
    then what b will be called, "runtime constant" (sounds odd).

    I once read on a post here (or article) that the
    compiler will replace any variable name you set in
    the switch case with the actual value. That is why
    it
    works on 'a' but not on 'b'. At compile time the
    compiler only knows the value of 'a'.
    That is not why you can use a but not b for the
    switch. The reason is that the compiler knows the
    value of a but not of b.
    What's the difference?

  • Class loading and Compile time constants

    Hi,
    I am not sure if this is the right place for basic questions. I would appreciate any help.
    From my understanding, the compile time constants are folded into the byte code during compilation. ( E.g. static final int MAX = 10; ). When I access a compile time constant from a different class, I can see that the class that holds the constant is not loaded at all. ( using -verbose:class option )
    Now, my question is, how does JVM access the class that holds the constant without loading it ?! Without the class being loaded, how can the JVM get a binary representation of the same ? What am I missing here ?
    thanks,
    Soumya.

    class A {
      public static final int X = 10;
    class B {
      void foo(int n) {
        switch n {
          case A.X:
            yadda();
    }The value of X (10) from class A is "folded" into the bytecode of class B.

  • Trouble adding a web url link to an existing file: 1046: Type was not found or was not a compile-time constant:

    Hi There,
    We're trying to add a simple link to an existing Flash file. There looks to be at least 7 separate .as files and a separate swf that loads the main swf which all seems overly complex for what is essentially a page with six buttons on it.
    However, we need to add a URL to some of the text. So we converted the text to a button, added an instance name of <ssbpurchasetickets_btn> then added the following Actionscript into the actions layer on the frame the text/button appears:
    ssbpurchasetickets_btn.addEventListener(MouseEvent.CLICK, ssbButtonPurchase);
    function ssbButtonPurchase(event:MouseEvent):void
    navigateToURL(new URLRequest("http://www.url.com/tickets.html"));
    When we publish the file we get the following error which seems to cascade into a whole bunch more errors:
    Description: 1046: Type was not found or was not a compile-time constant: MouseEvent.
    Source: function ssbButtonPurchase(event:MouseEvent):void
    We added "ssb" onto the button and functions to ensure there were no conflicts but the same thing occurred. If we copy the button into a new file everything works so it must be conflicting with something in the main files.
    Any help would be MUCH appreciated!!!!
    Cheers

    Thanks for the reply Ned,
    The file is set to use AS3 and I'm pretty sure the original should be set to AS3 as the .as files look like AS3 syntax to me - here's a sample:
    protected function handleWwrdButtonClick(e:ButtonEvent):void {
    Browser.open(globalVar.xml.wwrd.item[0].@url, globalVar.xml.wwrd.item[0].@target);
    OmnitureTracker.trackFeaturedContentClick('http://www.url.com/movies/international', 'wwrd_button');
    timer.stop();
    timer.removeEventListener(TimerEvent.TIMER, onTimer);
    I'm wondering if all the Actionscript has be placed into one of the .as files as there isn't any Actionscript in the Flash project - a part from the odd stop()
    Really stuck on this one (I'm not an expert at all) so any help in deciphering the project would be much appreciated.
    Cheers

  • 1046: Type was not found or was not a compile-time constant: Event.

    I am more than a little frustrated.  I'm using Flash Professional CS5.5, attempting to publish ActionScript 3.0 for FlashPlayer 10.2
    My code begins with:
    import flash.events.MouseEvent;
    import flash.events.Event;
    import flash.events.KeyboardEvent;
    import flash.utils.Timer;
    import flash.events.TimerEvent;
    Then much later I have:
    teamFourCar_mc.addEventListener(Event.ENTER_FRAME, trackPosition);
    function trackPosition (event:Event)
    and I keep getting a compiler error:
    Scene 1, Layer 'actions', Frame 1, Line 434
    1046: Type was not found or was not a compile-time constant: Event.
    I have imported the class "Events".  I have successfully used the same construction in other scripts... in fact, virtually the same construction is included in Code Snippets as Fade In and Fade Out.  Adding ":void" after (event:Event) makes no difference.  I have Googled - to no avail - and spent the better part of a day reading through the on-line help files, but the solution is still eluding me.
    It's probably so simple I'm going to smack myself in the forehead and mutter "Duh!" when I find a solution...
    If you can do anything to hasten that event (no pun intended) I (with the possible exception of my forehead) will be very grateful.
    TIA
    Terry

    Sinious:
    The entire code of the main movie clip is at http://pastebin.com/JYfLUhh1
    A sample of one of the four "problem" movie clips is at http://pastebin.com/gQGDyngx
    There is nothing wrong with the "problem" clip.  The problems are in the main movie clip:
    Scene 1, Layer 'actions', Frame 1, Line 427
    1046: Type was not found or was not a compile-time constant: Event.
    Scene 1, Layer 'actions', Frame 1, Line 612
    1046: Type was not found or was not a compile-time constant: Event.
    Scene 1, Layer 'actions', Frame 1, Line 1819
    1046: Type was not found or was not a compile-time constant: Event.
    There are the only three occurrences of a function with (event:Event).  Two are ENTER_FRAME (427 & 1819) The other is COMPLETE from Loader.info
    Auto format reported a syntax error "near 'if(movingCar.currentFrame == (dieRoll * 24) + movingCarPosition)' " but I can't detect what, if anything, is wrong with it.
    I'm not an experienced developer... in fact, the last programming I did before taking up Flash three months ago was with QuickBasic under DOS 6.2... therefore, please try not to roll your eyes too much when you see how inelegant the code is.
    I have a working version, but it's over 7,000 lines and a memory hog.  I'm trying to make it more elegant and more efficient.  BTW, the three (event:Event) functions are in the working version in more or less the same places, with the same calling code.
    I hope you can figure it out.
    Thank you in advance

  • Type was not found or was not a compile-time constant?

    Hi guys,
    I'm going nuts. I've got this movieclip that I made into a
    button with ActionScript. When clicked, it
    should go to a frame in my main timeline labeled "beansbus",
    but whenever I try to test the movie out, Flash
    gives me this error:
    1046: Type was not found or was not a compile-time constant:
    bus.
    I've looked around on the internet and I've been told that
    this error can
    crop up if the instance name is the same as a library object.
    That WAS the
    problem, but I renamed the library object to Cutebus, so that
    should have fixed it, I hope. There was another fix that involved
    something called TextFields in my movieclip, but I don't have
    those...
    My code looks like this, which was copied and pasted from an
    in-class tutorial that DOES work, with no problems.
    Thanks in advance for any light you can shed on this.

    actually the error:
    quote:
    TypeError: Error #1009: Cannot access a property or method of
    a null object reference. at
    beans_fla::MainTimeline/frame1()[beans_fla.MainTimeline::frame1:3]
    may not obviously give the line number at first
    glance, but it does! 'frame 1:3' refers to frame 1, line 3. which
    if your code post was accurate to line numbers, refers to:
    quote:
    bus.stop();
    so i'd suggest looking at your bus clip and
    ensuring that you have correctly defined its instance name. Also,
    make sure you have this correctly defined in each keyframe that the
    clip appears.

  • Help! "1046: Type was not found or was not a compile-time constant:TimerEvent."

    I am getting the followiing error in my main document class:
    "1046: Type was not found or was not a compile-time constant:TimerEvent."
    It's showing in line 47 and 54 (in red below). Any help would be appreciated. BTW, this is my first time creating a main document class since graduating to class files!:
    package
        //**************** IMPORT STATMENTS *********************
        import flash.display.MovieClip;
        import com.greensock.TweenLite;
        import flash.utils.Timer;
        public class Main extends MovieClip
            //***************** Variables ***************************
            /*private var appStoreURL:URLRequest = new URLRequest("http://itunes.apple.com/us/artist/quackenworth/id518210161");
            private var facebookURL:URLRequest = new URLRequest("http://www.facebook.com/quackenworth");
            private var twitterURL:URLRequest = new URLRequest("http://www.twitter.com/quackenworth");*/
            private var MainScene:Main = new Main();
            private var PopUp_MoreApps:MoreApps_mc = new MoreApps_mc();
            private var PopUp_About:About_mc = new About_mc();
            //*****SPLASH SCREEN ***
            private var mc_timerSplash:Timer;
            private var splashScreen:mcSplashScreen;
            //*****************CONSTRUCTOR CODE ***********************************************************************************
            public function Main()
                mc_timerSplash = new Timer(3000,1);
                mc_timerSplash.addEventListener(TimerEvent.TIMER,  StartTimer);
                //When timer is finished stop the timer;
                mc_timerSplash.addEventListener(TimerEvent.TIMER_COMPLETE, timerCompleted);
                splashScreen = new mcSplashScreen();
                 addChild(splashScreen);
                splashScreen.x = stage.stageWidth / 2;
                splashScreen.y = stage.stageHeight / 2;
                mc_timerSplash.start();
            //*********** FUNCTIONS *********************************
            private function timerCompleted(e:TimerEvent):void
                    mc_timerSplash.stop();
                    mc_timerSplash = null;
            private function StartTimer(e:TimerEvent):void
                TweenLite.to(splashScreen, 1, {alpha:0, onComplete: SplashScreen});
            private function SplashScreen():void
                removeChild(splashScreen);
                addMainScene();
            private function addMainScene():void
                addChild(MainScene);
                MainScene.x = 489;
                MainScene.y = 350;
                //TweenLite.from(MainScene.wbbIntro_mc, .5, {alpha: 0});
                TweenLite.from(MainScene, 1, {alpha:0});
                TweenLite.to(MainScene.girls_mc, 1, {y:395, delay:.3});
                TweenLite.to(MainScene.boys_mc, .5, {y:396, delay: .6});
                TweenLite.to(MainScene.Joe_mc, .5, {y:339, delay: 1});
                TweenLite.to(MainScene.Paul_mc, .5, {y:322, delay:1.2});
            private function removeMainScene():void
                removeChild(MainScene);
                TweenLite.to(MainScene.girls_mc, .1, {y:690});
                TweenLite.to(MainScene.boys_mc, .1, {y:693});
                TweenLite.to(MainScene.Joe_mc, .1, {y:636});
                TweenLite.to(MainScene.Paul_mc, .1, {y:619});

    Now that the error is solved, when I test nothing happens. I just get a blank screen.
    What is supposed to happen? When the program opens a splash screen should be added for 3 seconds and then fade out. Then some main screen movie clips should be added to the stage.

  • Compile time constant

    what is compile time constant
    1. final int a=9;
    2 final int b
    b=9;
    is 2 statement not a compile time constant

    Screen13Name wrote:
    but we cannot change its value then how it is not a constantThe term "compile-time constant" has a very specific meaning and very specific implications in the Java language.
    Just because something isn't a compile-time constant doesn't mean that it can be changed.

  • 1046:  not a compile-time constant: TimerEvent.

    I know this is simple but I just cannot see what I am doing
    wrong
    it is in reference to "public function
    moveClip(event:TimerEvent):void {"
    any help is appreciated .
    my code is attached
    thank you

    I am old .. and I guess I just see what I want to see ...ty
    for your help
    I moved it to AS3 ...
    I added the timer change found a few more errors and
    then I got same error ...

  • 1046: Type not a compile-time constant: TimerEvent.

    I have a simple space ship in an fla
    have this .as file
    but still getting the error
    related to the line "public function
    moveClip(event:TimerEvent):void {"

    instead of using
    import flash.events.TimerEvent.*;
    use
    import flash.events.TimerEvent;
    and you probably need
    import flash.utils.Timer;

  • Initializer element is not a compile-time constant in Xcode

    hi.......Every one
    ModelController.h
    #import <Foundation/Foundation.h>
    @interface ModelController : NSObject
    @property(nonatomic , strong)NSArray *states_Array;
    @end
    ModelController.m
    #import "ModelController.h"
    @implementation ModelController
    @synthesize states_Array;
    states_Array = [[NSArray alloc]initWithObjects:@1,@2,@3, nil];
    @end
    Now i want to access these array in MY TableViewController at cellForAtIndexPath
    Thanks InAdvance

    If you're using Flex 3.4 SDK, put only AdobeSpellingEngine.swc and AdobeSpellingUI.swc in your libs folder. (AdobeSpellingUIEx.swc is for Flex 4)
    For more details, please refer to the release notes
    http://labs.adobe.com/technologies/squiggly/releasenotes.html
    Hope this helps.

  • How can i read the timestamp of my *.swf's compile time?

    Hi,
    sometimes i run into the problem that my builds from FlexBuilder are not refreshed/rebuilt properly due to many reasons (compile errors, ...).
    To be able to determine if the build I'm debugging right now I'd simply like to display the timestamp of the compile time of my app within itself.
    Thought already about accessing the file properties through the FileSystem...but come on there must be another way to get that info...
    Searched also inside the LiveDocs for compiler constants that can be read but found nothing that matches my needs, yet.
    Thank's for any help or suggestion!
    - Michl

    Same question w/ a twist, is it somehow possible to get FLEX compiler to understand and evaluate something like this:
    -define+=COMPILE::Timestamp,"new Date()"
    Obviously it doesn't work otherwise I would have used it and proposed it as a solution myself.
    But I was wondering if there are some tweaks to trick the framework into evaluating this?
    Or writing this expression itself somehow differently to get it evaluated?

  • Compile-time arithmetics

    Hi!
    Could anybody explain me pls what is compiler optimization in regard to the code below. Why compile-time error is not thrown?
    class Compiler
         final static int i1 = 10;
         final static int i2 = 0;
         final static int i3 = i1/i2;
         final static int i4 = 10/0;
         public static void main (String args[])
              System.out.println(i3+" "+i4);
    }

    Actually, the compiler will check for constant expressions, and compute the value during compilation instead of at runtime. When it is the case that the computation would result in an ArithmeticException, the compiler will skip the optimization and insert the actual code. Dividing by zero is not a syntactical error, so while it prevents optimizations, it should not prevent a class from compiling.

  • Is there a 'compile time' if/else statement in LabVIEW

    I have some LabVIEW software that includes subVIs to read from and write to digital IO lines. However, I need to also be able to run this software on systems which don't have an IO card (or associated drivers) installed and so I want to be able to allow the software to be on PCs that do or don't have the drivers installed.
    Optimally, I would like to modify the software so that at runtime, by reading the settings in a configuration file, a boolean is set to determine whether the IO functions are called. I tried this but, unfortunately, am getting error messages when I try and start up the software due to the lack of the 'nidaq32.dll' file on the target PC. I'm guessing this is because the subVIs are only within case structures and so must be loaded into memory regardless of whether they are to be used.
    Is there any way around this problem? If I were writing this in C I guess I would use '#if' statements to include/exclude the IO functions at compile time. Is there an equivalent in LabVIEW? I guess my options are:
    1. Finding some way of allowing the IO functions to be included at runtime though I'm thinking this might not be possible.
    2. Include/exclude the IO functions at compile time with some LabVIEW equivalent of the C '#if' preprocessor directive.
    3. Give in and install the nidaq32.dll file with the software.
    Just to complicate matters, I'm currently running LabVIEW 5.0.1 (I do plan to upgrade soon) so am limited to the functions available in this version.
    Thanks.

    CAS wrote:
    Just to complicate matters, I'm currently running LabVIEW 5.0.1 (I do plan to upgrade soon) so am limited to the functions available in this version.
    That's the main problem.
    On newer versions you can:
    define simulated devices (http://zone.ni.com/devzone/cda/tut/p/id/3698)
    use the conditional disable structure (see e.g.: http://zone.ni.com/devzone/cda/tut/p/id/3046, (see section 6))
    Time to upgrade!
    Message Edited by altenbach on 06-21-2007 07:32 AM
    LabVIEW Champion . Do more with less code and in less time .

Maybe you are looking for

  • Attachments missing in mail.app

    I have noticed the following problem with an imap account: I am looking at a message that has an attachment but the attachment is not shown in mail.app. In its place there is a generic graphic with a question mark. I right-click, choose "Download Ima

  • Bill Presentment Architecture

    Bill Presentment Architecture Hi In the document we found that BPA has seeded 7 templates: Default Invoice Template, Default Oracle Service Contracts Template, Default Credit Memo Template, Default Debit Memo Template, Default Chargeback Template, De

  • Error in trying to run a seeded page in Jdev

    Hi Gurus, Im trying to run a seeded page in Jdev, I have copied all the dependencies to my Jdev home. But when I tried to running it I get the error below. I haven't done any code changes to the page yet. Please help. Thanks. ## Detail 0 ## java.lang

  • I converted a PDF to Word

    I converted na PDF to Word & it came back all dis organized

  • Border around image

    How do I take the border around the image away: http://marketingsource.businesscatalyst.com/lists/business?Preview=True need help ASAP!