Why is casting necessary here?

hi all, take the following code:
int i=-20;
final int j=20;
final int k=i;
byte b1= j;
byte b2= k;
byte b3= i;after i complied it, i got two errs. at b2 and b3, i solved that by casting.
but why is casting necessary here in contrast with b1?
thunx

You are trying to narrow an int to a byte.
This is acceptable, but only when the following conditions are met (JLS � 5.2):
1 - The expression is a constant expression of type byte, short, char or int.
2 - The type of the variable is byte, short, or char.
3 - 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.
In your example, your assignment to b1 uses a constant expression (j[b], which is final).
Your assignments to b2 and b3 do not use constant expressions (b3 is assigned from i, which is not final; b2 is assigned from k - which although final, is based on i, which is not).

Similar Messages

  • Creating an Account on Azure... Why is it necessary to give any credit card information? Do they charge something?

    Hi,
    I am new to cloud and find azure good to work with clouds. But I was trying to create trial an account there and it is asking for credit card. Please tell me if this is trial then why it is necessary to give the card details? Moreover, being a trial version,
    many of us don't have any cards these days. So till that time we have to wait for the card? Please provide some facility to learn and give some period of trial without any card details.
    Thanking you.
    Regards,
    Syed

    Hi,
    Please have a look at Azure free trial FAQ:
    http://azure.microsoft.com/en-gb/pricing/free-trial-faq/, We use the phone number and credit card for identity verification. We want to make sure that real people are using Azure. We
    do not bill anything on the credit card. So, please wait for the card. If you are a student and don't have a card, please try this link:
    http://www.WindowsAzurePass.com/azureu, refer to
    http://blogs.msdn.com/b/mast/archive/2013/10/12/windows-azure-30-day-s-free-trial-uncovered.aspx for more details.
    Best Regards,
    Jambor
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Why is it necessary to make the block synchronized while iteratiing

    Why is it necessary to make the block synchronized while iteratiing thru Synchronization Wrappers?
    here is the code sample for same:
    Collection c = Collections.synchronizedCollection(myCollection);
    synchronized(c) {
    Iterator i = c.iterator(); // Must be in synchronized block!
    while (i.hasNext())
    foo(i.next());
    }

    If at the first place I am getting all the methods synchronized by calling
    Collection c = Collections.synchronizedCollection(myCollection);
    that means no two threads can enter the data structure of this collection, I am not getting how ConcurrentModificationException will be thrown while iterating thru this collection?
    Can u please explain in a little depth?

  • Why use the symbol "|" here?

    Why use the symbol "|" here?
    SQL> @D:/temp/emp_package.sql|

    Hi,
    To me it seems that some parameter is passed (but i doubt why somebody would be passsing "|") to the sql file during the run time.
    One reason could be to tell the file what is the deliminator. Is this the case for you?
    Regards
    Anurag Tibrewal.

  • Why use symbol "!" here?

    Why use symbol "!" here?
    if (!contactOld.getWorkAddress().equals(
    public void entryUpdated(MapEvent event)
    Contact contactOld = (Contact)event.getOldValue();
    Contact contactNew = (Contact)event.getNewValue();
    StringBuffer sb = new StringBuffer();
    if (!contactOld.getHomeAddress().equals(
    contactNew.getHomeAddress()))
    sb.append("Home address ");
    if (!contactOld.getWorkAddress().equals(
    contactNew.getWorkAddress()))
    sb.append("Work address ");
    if (!contactOld.getTelephoneNumbers().equals(
    contactNew.getTelephoneNumbers()))
    sb.append("Telephone ");
    sb.append("was updated for ").append(event.getKey());
    System.out.println(sb);
    }

    http://java.sun.com/docs/books/tutorial/java/nutsandbolts/operators.html
    :Rob:
    Coherence Team

  • Why it is necessary that public class name should  same as filename in java

    hi,
    why it is necessary that public class name should same as filename in java.
    As I know that it is a convention, but I want the information why this convention is made.
    thanx.

    user13445117 wrote:
    but suppose if i am creating a java file with default access modifire then we do not need to save the file name as a class name.So, your question is "Why does the rule about top-level classes being in a file of the same name apply +only+ to public classes"?
    If it were applied to all classes, then we could never have two top-level classes in the same file. Doing that is generally not a good idea, but it might be useful from time to time. EJP already told you why it applies to public classes, and, since these are the most common by far, it's a fair compromise that it apply to them but not to other classes.
    Was this the reason the original designers did it that way 15 or so years ago? Don't know, don't care, but it's one plausible explanation. Maybe it was just a balance between simplicity and clarity on the one hand, and flexibility on the other.
    It's certainly not something I can see caring that much about, unless you're doing an in-depth history on Java, or writing an in-depth treatise on computer language and compiler theory.

  • Plugin-container.exe : what is it, why is it necessary, can I delete it

    Continued from the "plugin-container.exe : what is it, why is it necessary, can I delete it" thread:
    1) When people say Firefox uses up a lot of CPU/Memory, they are telling the truth. Tools like Task Manager and Process Explorer show you how much CPU/Memory Firefox is using up. Stop calling people liars when they say Firefox is using up X Memory. Stop making baseless accusations like "you're running other programmes that are causing your CPU to skyrocket and Firefox to freeze". Task Manager and Process Explorer don't lie. Take yourself off the thread because you're not helping anyone, you're creating anger and hatred, you're basically trolling. If you have no valid advice to offer, keep your mouth shut and stay away instead of launching into the "you're a liar" nonsense.
    2) Stop typing in caps
    3) Refrain from using profanity and ad hominem attacks
    4) If you claim you're abandoning Firefox for another browser, fine: now get off the board and go away instead of posting inflammatory hatred against Mozilla since you're no longer using Mozilla
    5) Stop attacking and/or ignoring the advice of Mozilla representatives like Morbus
    6) Morbus: the Firefox Safe-Mode advice you frequently dispense is the most rejected advice because most people do not want to mess with their browsers, especially people who are not not knowledgeable about safe-mode, add-ons, disabling, etc. I fully agree that people must learn how to diagnose the problems on their own and find solutions on their own, but not all people are capable of learning how to do that. Computers are easy for many people, but not all people. The Safe-Mode solution appeals to a '''minority '''of people who are comfortable with picking apart their browser and picking apart other things to find solutions, not the majority, who fear making things worse.
    == This happened ==
    Every time Firefox opened
    == Today 6/22/2010

    7) Stop telling people to remove add-ons and plug-ins and scripts. Firefox was made specifically to enable to build their own browsers. Firefox was made for the purpose of allowing people use all the add-ons and plug-ins and scripts they wanted. No other browser offers that range of add-on/plug-in/script support. Removing the add-ons and plug-ins and scripts eliminates the purpose of Firefox. If Mozilla representatives want to insist that removing add-ons and plug-ins and scripts are the solution, then Mozilla is telling us that its browser is no different from IE or Chrome, in which case Mozilla has given us a reason to stop using Mozilla.

  • I recently purchased tunes with iTunes gift card.  I still have $ left on my card and now I'm asked to verify my account. Why is this necessary?

    I recently purchased tunes with iTunes gift card.  I still have $ left on my card and now I'm asked to verify my account. Why is this necessary?

    Because iTunes simply wants you to verify your name & address is correct in your account info.

  • In another words, why use Parameter Macros here ?

    Why do not pass actual values directly for the parameters <high-units> and <expiry-delay> ?
    In another words, why use Parameter Macros here ?
    <local-scheme>
    <scheme-name>example-backing-map</scheme-name>
    <eviction-policy>HYBRID</eviction-policy>
    *<high-units>{back-size-limit 0}</high-units>*
    *<expiry-delay>{back-expiry 1h}</expiry-delay>*
    <flush-delay>1m</flush-delay>
    <cachestore-scheme></cachestore-scheme>
    </local-scheme>
    This fraction come from the following file:
    <?xml version="1.0"?>
    <!DOCTYPE cache-config SYSTEM "cache-config.dtd">
    <cache-config>
        <caching-scheme-mapping>
            <cache-mapping>
                <cache-name>test</cache-name>
                <scheme-name>example-near</scheme-name>
            </cache-mapping>
        </caching-scheme-mapping>
        <caching-schemes>
            <distributed-scheme>
                <scheme-name>example-distributed</scheme-name>
                <service-name>DistributedCache</service-name>
                <backing-map-scheme>
                    <local-scheme>
                        <scheme-ref>example-backing-map</scheme-ref>
                    </local-scheme>
                </backing-map-scheme>
                <autostart>true</autostart>
            </distributed-scheme>
            <near-scheme>
                <scheme-name>example-near</scheme-name>
                <front-scheme>
                    <local-scheme>
                        <eviction-policy>
                            <class-scheme>
                                <class-name>MyEvictionPolicy</class-name>
                            </class-scheme>
                        </eviction-policy>
                        <high-units>10</high-units>
                    </local-scheme>
                </front-scheme>
                <back-scheme>
                    <distributed-scheme>
                        <scheme-ref>example-distributed</scheme-ref>
                    </distributed-scheme>
                </back-scheme>
                <invalidation-strategy>all</invalidation-strategy>
                <autostart>true</autostart>
            </near-scheme>
            <local-scheme>
                <scheme-name>example-backing-map</scheme-name>
                <eviction-policy>HYBRID</eviction-policy>
                <high-units>{back-size-limit 0}</high-units>
                <expiry-delay>{back-expiry 1h}</expiry-delay>
                <flush-delay>1m</flush-delay>
                <cachestore-scheme></cachestore-scheme>
            </local-scheme>
        </caching-schemes>
    </cache-config>Edited by: qkc on 30-Nov-2009 08:32

    qkc wrote:
    Where do back-size-limit and back-expiry come from?You can specify them as init parameters within the cache-mapping.
    <cache-config>
      <caching-scheme-mapping>
        <cache-mapping>
          <cache-name>test</cache-name>
          <scheme-name>example-near</scheme-name>
          <init-params>
            <init-param>
              <param-name>back-size-limit</param-name>
              <param-value>...</param-value>
            </init-param>
            <init-param>
              <param-name>back-expiry</param-name>
              <param-value>...</param-value>
            </init-param>
          </init-params>
        </cache-mapping>
        ...Best regards,
    Robert

  • Cast required here - why?

    Hi all. I was looking into compile time constants on the web and came across
    this little snippet of code which compiles fine:
    class TestVar {
    public static void main(String[] args) {
    final int i = 90;
    byte b = i;
    }When it is changed to:
    class TestVar {
    public static void main(String[] args) {
    final int i;
    i = 90;
    byte b = i; //this requires a cast (byte) to compile...
    }It requires an explicit byte cast when the assignment byte b = i; is made.
    Yet how come this isnt the case in the first code snippet?
    Thanks in advance
    Edited by: shamrock08 on Apr 28, 2008 11:46 AM

    public class Scratch {
      public static void main(String[] args) throws Exception {
        final int i = 127;    // 0-2 below
        final int j;
        j = 126;    // 3-5 below
        byte b1 = i;    // 6-8 below
        byte b2 = (byte)j;    // 9-11 below
        int k = j;    // 13-14 below
    :; javap -c -classpath classes Scratch
    public static void main(java.lang.String[])   throws java.lang.Exception;
      Code:
       0:   bipush  127
       2:   istore_1    // store the literal 127 into i
       3:   bipush  126
       5:   istore_2    // store the literal 126 into j
       6:   bipush  127
       8:   istore_3    // store the literal 127 (NOT i's value) into b1
       9:   iload_2
       10:  i2b    // cast j's value to a byte
       11:  istore  4    // store the result of the above (NOT the constant 126) into b2
       13:  iload_2
       14:  istore  5    // store the value of j (NOT the constant 126) into k
       16:  return
    }When the final variable is initialized at declaration time, any later reference to that variable's value simply uses the constant directly, rather than reading that variable's value. When the final variable is assigned later, any refernce to that variable's value has to read the variable to get the value, regardless of the type of the variable being assigned to.
    For the question at hand, the compiler does not distinguish between
    final int i;
    i = 123;and
    final int i;
    if (something) {
      i = 123;
    else {
      i = 123456789;
    }so the compiler doesn't know whether i's value will fit into a byte.
    Edited by: jverd on Apr 28, 2008 12:17 PM
    Edited by: jverd on Apr 28, 2008 12:21 PM

  • Is a crossover cable necessary here

    I am trying use an ethernet cable to connect my iMac G5 directly to an Acer laptop running Windows XP. Have turned on SMB file sharing on the Mac, have a file for sharing set up on the laptop. Everything I've read in the discussions and Apple's support pages seem to indicate that the Mac should auto-detect the laptop, or that I should be able to get my Mac to show up on my laptop's "My Network Places" using the connection wizard or other method, but it's just not happening. What I've read in the discussions and suppport area also indicate that a crossover cable shouldn't be necessary -- or could that not be the case? If you have any insight into why I can't get this to work, I'd be most grateful if you could share it.
    Thanks,
    Dave
    iMac G5 Mac OS X (10.3.9)

    Thanks Barbara, that helped a bit. But actually what I was really missing was a little fact that you need know: how to give an IP address to each computer when they are just two machines connected with no internet connection. In case anyone reading this needs to know, the following on how to name the ip address for the Windows machine here from http://www.smartcomputing.com/Editorial/article.asp?article=articles/2004/w1510/ 38w02/38w02.asp :
    "Click Start, My Network Places, and Local Area Connection.
    Click the Properties button on the General tab of the Local Area Connection Status window. Scroll through the list of connections, if necessary, and click Internet Protocol (TCP/IP). Then click the Properties button.
    On the next window, click the Use The Following IP Address radio button and type your IP address and subnet mask. For home or office networks, you should use internal IP addressing, in the form of 192.168.0.x (where x represents any number from 1 to 256). For example, if you use 192.168.0.1 for the first computer, use 192.168.0.2 on the second computer. For this IP range, your subnet on both PCs must be 255.255.255.0.
    Click OK and Close. "
    To give the Mac its ip address you go to the Finder under Network, and TCP/IP -- I hope Apple can put this in their support pages, would have saved me hours.

  • Why has CAST(FieldName to float) failed in view but not in SELECT?

    I've just solved a problem but I'm still not sure what the problem is!
    I have a data (staging) table with all values stored as text. The data is converted to the correct data-type and also aggregated somewhat in a view. A select statement with the conversion works. A select statement with the conversion and aggregation (GROUP
    BY) works. Creating a view of the conversion and aggregation works. However, on selecting from the view (e.g. SELECT TOP 1000 * FROM ViewName) it fails saying it cannot convert from varchar to float. There are no visible characters in the field apart from
    numbers between 0 and 9, a decimal point and sometimes a leading minus sign (-).
    The fix? Cast to money and then cast to float.
    The problem? I don't know! What was the problem? Some of the values had up to 10 decimal places. Was that a problem? Was it really an overflow error masquerading as conversion error? The longest strings present were:
    -2.609763091
    -0.082456066
    -0.674010546
    -2.563428427
    -0.016109637
    -0.313600766
    -0.104452264
    -0.853811384
    -0.302529502
    -0.000362354
    -0.002961949
    -0.319269185
    -0.001970796
    Would really like to know what caused this so I can spot it in future before it happens.
    Cheers.
    JCEH

    One possibility is that the two execution plans are different.  The logical order of the way SQL processes the clauses a SELECT query is FROM, ON, OUTER, WHERE, GROUP BY, CUBE | ROLLUP, HAVING, SELECT, DISTINCT, ORDER BY, TOP.  (Actually that's
    what I learned, now there are some additional things like APPLY, but for our purposes we can ignore them).  The important thing to know is that that is the LOGICAL order, but SQL is allowed (and often does) go change that order to anything it wants as
    long as it returns the correct result. 
    So, for example, if your FROM clause a number of rows and some of those rows contain data which would cause a CAST (or anything else) in the SELECT clause to fail, but those rows are eliminated by your WHERE clause.  Then SQL could do
    FROM, WHERE, SELECT and the query works, or
    FROM, SELECT, WHERE and the query fails.  And, in general, you cannot control which plan SQL will use.
    So, for example, if you have a table named T with two integer columns I and J and some rows in the table have a value of 0 in the column J and you run
    SELECT I/J FROM T WHERE J<>0
    it might work and you might get a divide by zero error.  So one safe way to handle this is to write your query as
    SELECT I/(CASE WHEN J <> 0 THEN J ELSE NULL END) WHERE J<>0
    Another way would be to create a temp table and write an insert statement that inserted into that temp table only the rows where J<>0 and then do the query from the temp table.  Since that is two SQL commands, SQL is forced to do them in order,
    it cannot combine them and reorder the processing, that would look like
    Create Table #T(I int, J int);
    Insert Table #T(I, J)
    Select I, J FROM T WHERE J<>0;
    Select I/J From #T;
    Drop Table #T;
    You could try doing the equivalent of one of those to your query and see if that makes the problem go away.
    Now I know you are going to ask "Why did the view use to work and it doesn't anymore?" and "Why does using the view and the table return different results".  My guess is that you are getting different plans for the view and the table,
    why that is, I don't know, it is often difficult to answer that type of question.  My best guess for why the view used to work, then you ALTERED it, and then changed it back to the original form and it fails even though it is exactly the same as the old
    view that was working is, when you had the old view, then was a cached execution plan that was working.  That execution plan might have been created a good while ago.  When you ALTERED it, you, of course, got a new plan.  Then when you ALTERED
    it back to the original form, it no longer had the plan it had been using, so had to create a new one, and this new plan was different than the old one.
    Finally, if this is the cause of your problem, then you are not guaranteed that the convert to money, then to float is a permanent fix.  If you have column headers which cannot be converted to either money or float, then it could be the convert to money
    then to float is enough to get SQL to do the WHERE first, then the SELECT.  But there is no guarantee that will be true forever.  Changes in your data distribution and release level of SQL might make that version do the select first and then the
    where.
    Tom

  • Why narrow casting is must before doing wide casting

    Hi everyone,
    I know the concept of wide casting ( assign/pass super class instances to subclass instances). So then why we need to do narrow casting before doing wide casting in our logic. I am just struggling into this concept from last 3 days. I have read many thread and blog but did not get satisfactory answer.
    Regards,
    Seth

    Hello Seth
    You do not need to do narrow casting. But, if you assign an instance of a super class to variable of subclass and try to run a subclass' method on that instance (of superclass) you will get an exception. Because super class does not have a mentioned method.
    Example:
    CLASS lcl_vehicle DEFINITION.
    ENDCLASS.
    CLASS lcl_car DEFINITION INHERITING FROM lcl_vehicle.
      DATA engine TYPE string VALUE 'has_engine'.
    ENDCLASS.
    DATA:
      lo_vehicle TYPE lcl_vehicle,
      lo_car TYPE lcl_car.
    CREATE OBJECT lo_vehicle.
    CREATE OBJECT lo_car.
    WRITE lo_car->engine.
    lo_car ?= lo_vehicle.
    WRITE lo_car->engine.
    regards

  • Why action not good here???

    please in the toolbarPanel class why the
    line button.addActionListener(new ButtonListener() );
    not affect on the button .
    please any one answer me .
    the code here:
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Dimension;
    import javax.swing.JFrame;
    import javax.swing.JMenu;
    import javax.swing.JMenuBar;
    import javax.swing.JMenuItem;
    import javax.swing.JPanel;
    import javax.swing.SwingUtilities;
    public class Paint extends JFrame {
        ToolbarPanel toolbarPanel;
        private DrawingPanel DrawPanel;
        private JMenuBar bar;
        private JMenu fileMenu;
        private JMenuItem openItem,  saveItem;
        private JPanel panel;
        public Paint() {
           DrawPanel = new DrawingPanel();
            toolbarPanel = new ToolbarPanel(DrawPanel);
            panel=new JPanel();
            fileMenu = new JMenu("file");
            fileMenu.addSeparator();
            openItem = new JMenuItem("open");
            fileMenu.add(openItem);
            saveItem = new JMenu("save");
            fileMenu.add(saveItem);
            bar = new JMenuBar();
            setJMenuBar(bar);
            bar.add(fileMenu);
            add(toolbarPanel, BorderLayout.NORTH);
           DrawPanel.setBackground(Color.WHITE);
           add(DrawPanel, BorderLayout.CENTER);
            panel.setBackground(Color.GRAY);
            panel.setPreferredSize(new Dimension(200,300));
            add(panel,BorderLayout.EAST);
        private static void creatAndShowGUI() {
            JFrame frame = new Paint();
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.pack();
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
        public static void main(String[] args) {
            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    creatAndShowGUI();
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.BorderFactory;
    import javax.swing.JButton;
    import javax.swing.JPanel;
    import javax.swing.JToolBar;
    import javax.swing.border.TitledBorder;
    class ToolbarPanel extends JPanel {
        private JToolBar toolbar;
        private String[] labels = {"Line", "Oval", "Square", "Rectangle", "Polygan", "Triangle"};
        private JButton button;
        private DrawingPanel panel;
        public ToolbarPanel(DrawingPanel panel) {
            this.panel = panel;
            toolbar = new JToolBar();
            for (int i = 0; i < labels.length;++i) {
                button = new JButton(labels);
    toolbar.add(button);
    toolbar.add(button);
    button.addActionListener(new ButtonListener());
    add(toolbar);
    TitledBorder title;
    title = new TitledBorder("Shapes");
    title = BorderFactory.createTitledBorder(title);
    setBorder(title);
    code}
        private class ButtonListener implements ActionListener {
            public void actionPerformed(ActionEvent e) {
                    if (e.getSource() == labels[0]) {
                        panel.draw(DrawingPanel.LINE);
    import java.awt.Dimension;
    import java.awt.Graphics;
    import java.awt.event.MouseAdapter;
    import java.awt.event.MouseEvent;
    import java.util.Vector;
    import javax.swing.JPanel;
    public class DrawingPanel extends JPanel {
        private int x1,  y1,  x2,  y2,  width_I,  width_F,  Height_I,  Height_F,  Oval_w,  Oval_h,  Oval_x,  Oval_y;
        public final static int LINE = 1,  OVAL = 2;
        private int shape;
        private Vector vLine,  vOval;
        public DrawingPanel() {
            vLine = new Vector();
            vOval = new Vector();
            addMouseListener(
                    new MouseAdapter() {
                        @Override
                        public void mousePressed(MouseEvent e) {
                            if (shape == LINE) {
                                x1 = e.getX();
                                y1 = e.getY();
                            if (shape == OVAL) {
                                width_I = e.getX();
                                Height_I = e.getY();
                                Oval_x = e.getX();
                                Oval_y = e.getY();
                        @Override
                        public void mouseReleased(MouseEvent e) {
                            x2 = e.getX();
                            y2 = e.getY();
                            if (shape == LINE) {
                                vLine.add(new Coordinate(x1, y1, x2, y2));
                            repaint();
                            if (shape == OVAL) {
                                width_F = e.getX();
                                Height_F = e.getY();
                                /*   if (width_F < width_I) {
                                Oval_x = e.getX();
                                if (Height_F < Height_I) {
                                Oval_y = e.getY();
                                /*  vOval.add(new Coordinate(width_I,Height_I,width_F,Height_F));*/
                                repaint();
            Dimension dimension = new Dimension(500, 300);
            setMinimumSize(dimension);
            setPreferredSize(dimension);
        @Override
        public void paintComponent(Graphics g) {
            super.paintComponent(g);
            for (int i = 0; i < vLine.size(); ++i) {
                Coordinate coordinate = (DrawingPanel.Coordinate) vLine.elementAt(i);
                g.drawLine(coordinate.x1, coordinate.y1, coordinate.x2, coordinate.y2);
            Oval_w = Math.abs(width_F - width_I);
            Oval_h = Math.abs(Height_F - Height_I);
            g.drawOval(Oval_x, Oval_y, Oval_w, Oval_h);
        public void draw(int shapeTodraw) {
            shape = shapeTodraw;
            repaint();
        private class Coordinate {
            private int x1,  y1,  x2,  y2;
            public Coordinate(int inx1, int iny1, int inx2, int iny2) {
                x1 = inx1;
                y1 = iny1;
                x2 = inx2;
                y2 = iny2;

    no my friend i don't take java in my class
    i learend it wit myself.
    plz answer to my question
    i try to do this but filled
    public void actionPerformed(ActionEvent e) {
            for(int i=0;i<labels.length;++i){
                    if (e.getActionCommand()==labels){
    panel.draw(DrawingPanel.LINE);
    }i wait your answer
    thanks                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Instance Initialization Question (Why Is It Required Here???)

    In the example below, I don't understand why instance initialization is required for the line below to succeed. Any chance someone can explain it to me? :) Thanks in advance.
    THIS IS THE LINE I'M REFERRING TO
    cost = Math.round(price);
    [java]
    //: c08:Parcel9.java
    // Using "instance initialization" to perform
    // construction on an anonymous inner class.
    // From 'Thinking in Java, 3rd ed.' (c) Bruce Eckel 2002
    // www.BruceEckel.com. See copyright notice in CopyRight.txt.
    import com.bruceeckel.simpletest.*;
    public interface Destination {
         String readLabel();
    public class Parcel9 {
         private static Test monitor = new Test();
         public Destination dest(final String dest, final float price) {
              return new Destination() {
                   private int cost;
                   // Instance initialization for each object:
                        cost = Math.round(price);
                        if(cost > 100)
                             System.out.println("Over budget!");
                   private String label = dest;
                   public String readLabel() { return label; }
         public static void main(String[] args) {
              Parcel9 p = new Parcel9();
              Destination d = p.dest("Tanzania", 101.395F);
              monitor.expect(new String[] {
              "Over budget!"
    [java]

    return new Destination() {
    };Here you define an anonymous local class. Anonymous classes can't have constructors, so if there are any operations that need to be done when an instance of the class is created, they have to go in the instance initializer block. (Like with regular classes, it's illegal to have anything but declarations in the class body.)
    But the particular line you refer to actually doesn't have to be there; it's possible to combine the declaration and assignment of the cost variable:    private int cost = Math.round(price);

Maybe you are looking for

  • Variable assignment in BEx Broadcaster

    I'm trying to broadcast a web template directly from the Broadcaster, and want to assign variables. I've tried Determine from Variant, and it works like a charm. As I understand it I should be able to enter the variables manually by using Determine H

  • 5th Gen. iPod cover seems to be shifting very slightly, what's with that??

    When I first bought my iPod, i could have sworn that the edges on the front part of the iPod (not an external cover, but the part that covers the internal iPod functions) were equal all around the side of iPod. For some reason or other now I am sure

  • JDBC connection detection failed in UNIX environment

    Now I am doing the connection detection to ORACLE but it failed in UNIX environment. I will put the error messages here bash-2.03$ java -Dbea.home=/bea utils.dbping ORACLE ecom31@cse oracle global Starting Loading jDriver/Oracle ..... Error encounter

  • Can't Create Statement Object - Help

    Hi: I'm using NetBeans 5.0 which is pointing at: Java\jdk1.5.0_07 The IDE can't see the Statement object: 'cannot find symbol Statement'. It won't compile. I've included: import java.* at the top of the file. It's not having a problem creating the co

  • FM to find out how many payrolls with deductions are left?

    I've been looking for a FM that will tell me how many pay periods are left that will have deductions taken out of them. For example, bi-weekly people get paid 26 times per year, however, benefits deductions come out on only 24 of those. I need to see