Unnecessary casting in TypeMapperRegistryImpl ?

Hi,
I was looking at the source code of com.sun.xml.rpc.encoding.TypeMapperRegistryImpl (Sun's implementation of TypeMapperRegistry) at http://www.koders.com/java/fid141228AEE2974D6FBB4640EB03FCFEFC1ACE07B7.aspx
and came across this method :
protected static boolean mappingSupportsEncoding(TypeMapping mapping, String namespaceURI) {
        String[] encodings = ((TypeMappingImpl) mapping).getSupportedEncodings();
        for(int i=0; i<encodings.length; ++i) {
            if (encodings.equals(namespaceURI)) {
return true;
return false;
The TypeMapping interface itself exposes the method getSupportedEncodings(); there is NO NEED to do the cast to TypeMappingImpl. What this casting does is effectively throw a ClassCastException whenever the mapping object is NOT an instance of TypeMappingImpl.
Since this method is called whenever anyone tries to register a new TypeMapping, this is preventing non TypeMapperImpl mappers from being registered.
Is this by design (Cannot think of any reason why) ?? Isn't JAX-RPC supposed to be extensible in terms of encoding (among others) ?
Any help will be greatly appreciated.
Raja

Syntax for casting in OO, is like this.
* References to the objects
  data: r_account type ref to lcl_account.
  data: r_checking type ref to lcl_checking.
* Is the account, a checking account?
   r_checking ?= r_account.
You will learn this when you get to ABAP OO. 
Regards,
Rich Heilman

Similar Messages

  • Unnecessary cast warning...I can't figure out why

    I've got my compiler warning me of unnecessary casts, and this method generates one of the warnings:
        public static<T> T doIt(T input) {
            Object result = null;
            return (T) result; // Warning: Unnecessary cast to type T for expression of type Object
        }Can anybody explain why it doesn't like me casting to type T? I get a compiler error if I don't make the cast.
    Thanks.

    I think that the article is a bit of a red herring in this particular case. Whilst it's true that erasure means that the generic type information is lost at runtime, generic type information most certainly is not lost at compile time - that's the whole point of generics - to be typesafe at compile time.
    In this case, we clearly have an Object reference, which could refer to any object (though in this case it refers to null), and it's being assigned to a T reference, hence the need for an explicit downcast. Remove it and you get the following error
        Warning:  line (5) [unchecked] unchecked cast
                           found   : java.lang.Object
                           required: Twhich is as expected, and illustates the point that the case is clearly not 'unnecessary'.
    Regarding Eclipse, if you can't find out the command line arguments to javac try creating an Ant build script to do the compilation for you. The execution log of the script will tell you exactly what was passed to javac, and it's resulting output. Furthermore, since support for Java 5.0 in the development branch of Eclipse is currenty under active development, many problems such as this are bound to crop up. When you do run up against another problems again, you can use the Ant build script to determine whether or not the problem lies with Eclipse or the JDK. If it's Eclipse, you've a better chance of having the problem resolved throught the Eclipse forums and/or bug tracker.

  • Generated SQL statement contains unnecessary cast

    I have a table containing a column of type decimal(10,0). Generated entity model maps this to a int32. When I perform a query on this field, for example
    test.Where(p => p.id = 10)
    the generated query contains the following
    where (Cast(id as number (19,0)) = 10)
    the prevents the server from using indexes on this column.
    How can i prevent this unnecessary cast?

    I follow your description but cannot reproduce the extra casting in the WHERE clause in the generated SQL.
    Are you using the lastest ODAC production version (11.2.0.3) ?
    When id column is defined as decimal(10, 0), it's indeed mapped to Int32 as you described.
    That's because decimal(10, 0) is actually number(10).
    10 is Int32 by default and ID column is already mapped to Int32. I don't see there is casting.
    The only way I can reproduce the extra casting is explicitly adding decimal casting to 10. For example,
    test.Where(p => p.id == (decimal) 10)
    Then I got the following:
    WHERE (10 = ( CAST( "Extent1"."ID" AS number(19,0))))
    But I don't think that's what you did.
    Would you please provide more details?

  • [svn] 1048: modules: Removing more unnecessary casts from my previous change.

    Revision: 1048
    Author: [email protected]
    Date: 2008-03-31 17:14:13 -0700 (Mon, 31 Mar 2008)
    Log Message:
    modules: Removing more unnecessary casts from my previous change.
    Modified Paths:
    flex/sdk/trunk/modules/compiler/src/java/flash/svg/SpriteTranscoder.java
    flex/sdk/trunk/modules/compiler/src/java/flash/swf/tools/as3/EvaluatorAdapter.java
    flex/sdk/trunk/modules/compiler/src/java/flash/swf/tools/as3/PrettyPrinter.java
    flex/sdk/trunk/modules/compiler/src/java/flex2/compiler/API.java
    flex/sdk/trunk/modules/compiler/src/java/flex2/compiler/PersistenceStore.java
    flex/sdk/trunk/modules/compiler/src/java/flex2/compiler/ResourceContainer.java
    flex/sdk/trunk/modules/compiler/src/java/flex2/compiler/SourcePath.java
    flex/sdk/trunk/modules/compiler/src/java/flex2/compiler/SymbolTable.java
    flex/sdk/trunk/modules/compiler/src/java/flex2/compiler/as3/Compiler.java
    flex/sdk/trunk/modules/compiler/src/java/flex2/compiler/as3/SignatureEvaluator.java
    flex/sdk/trunk/modules/compiler/src/java/flex2/compiler/as3/SignatureExtension.java
    flex/sdk/trunk/modules/compiler/src/java/flex2/compiler/as3/SyntaxTreeEvaluator.java
    flex/sdk/trunk/modules/compiler/src/java/flex2/compiler/as3/binding/DataBindingFirstPassE valuator.java
    flex/sdk/trunk/modules/compiler/src/java/flex2/compiler/as3/binding/TypeAnalyzer.java
    flex/sdk/trunk/modules/compiler/src/java/flex2/compiler/as3/reflect/Attributes.java
    flex/sdk/trunk/modules/compiler/src/java/flex2/compiler/as3/reflect/Method.java
    flex/sdk/trunk/modules/compiler/src/java/flex2/compiler/as3/reflect/Namespace.java
    flex/sdk/trunk/modules/compiler/src/java/flex2/compiler/as3/reflect/NodeMagic.java
    flex/sdk/trunk/modules/compiler/src/java/flex2/compiler/as3/reflect/TypeTable.java
    flex/sdk/trunk/modules/compiler/src/java/flex2/compiler/as3/reflect/Variable.java
    flex/sdk/trunk/modules/compiler/src/java/flex2/compiler/asdoc/ASDocExtension.java
    flex/sdk/trunk/modules/compiler/src/java/flex2/compiler/asdoc/ClassTable.java
    flex/sdk/trunk/modules/compiler/src/java/flex2/compiler/config/CommandLineConfigurator.ja va
    flex/sdk/trunk/modules/compiler/src/java/flex2/compiler/config/ConfigurationBuffer.java
    flex/sdk/trunk/modules/compiler/src/java/flex2/compiler/i18n/PropertyText.java
    flex/sdk/trunk/modules/compiler/src/java/flex2/compiler/media/SVGTranscoder.java
    flex/sdk/trunk/modules/compiler/src/java/flex2/compiler/mxml/Element.java
    flex/sdk/trunk/modules/compiler/src/java/flex2/compiler/mxml/analyzer/WebServiceAnalyzer. java
    flex/sdk/trunk/modules/compiler/src/java/flex2/compiler/mxml/dom/Scanner.java
    flex/sdk/trunk/modules/compiler/src/java/flex2/compiler/mxml/lang/NodeTypeResolver.java
    flex/sdk/trunk/modules/compiler/src/java/flex2/compiler/mxml/rep/Model.java
    flex/sdk/trunk/modules/compiler/src/java/flex2/compiler/swc/Digest.java
    flex/sdk/trunk/modules/compiler/src/java/flex2/compiler/swc/SwcCache.java
    flex/sdk/trunk/modules/compiler/src/java/flex2/compiler/swc/SwcGroup.java
    flex/sdk/trunk/modules/compiler/src/java/flex2/compiler/util/Benchmark.java
    flex/sdk/trunk/modules/compiler/src/java/flex2/compiler/util/IteratorList.java
    flex/sdk/trunk/modules/compiler/src/java/flex2/compiler/util/MD5Crypt.java
    flex/sdk/trunk/modules/compiler/src/java/flex2/compiler/util/QNameList.java
    flex/sdk/trunk/modules/compiler/src/java/flex2/compiler/util/VelocityManager.java
    flex/sdk/trunk/modules/compiler/src/java/flex2/linker/DependencyWalker.java
    flex/sdk/trunk/modules/compiler/src/java/flex2/tools/Compiler.java
    flex/sdk/trunk/modules/compiler/src/java/flex2/tools/DigestTool.java
    flex/sdk/trunk/modules/compiler/src/java/flex2/tools/MovieMetaData.java
    flex/sdk/trunk/modules/compiler/src/java/flex2/tools/PostLink.java
    flex/sdk/trunk/modules/compiler/src/java/flex2/tools/PreLink.java
    flex/sdk/trunk/modules/compiler/src/java/flex2/tools/oem/Library.java
    flex/sdk/trunk/modules/compiler/src/java/flex2/tools/oem/internal/OEMConfiguration.java
    flex/sdk/trunk/modules/compiler/src/java/flex2/tools/oem/internal/OEMReport.java
    flex/sdk/trunk/modules/swfutils/src/java/flash/fonts/BatikFontManager.java
    flex/sdk/trunk/modules/swfutils/src/java/flash/fonts/JREFontManager.java
    flex/sdk/trunk/modules/swfutils/src/java/flash/graphics/g2d/GraphicContext.java
    flex/sdk/trunk/modules/swfutils/src/java/flash/localization/XLRLocalizer.java
    flex/sdk/trunk/modules/swfutils/src/java/flash/swf/MovieMetaData.java
    flex/sdk/trunk/modules/swfutils/src/java/flash/swf/SwfDecoder.java
    flex/sdk/trunk/modules/swfutils/src/java/flash/swf/TagEncoder.java
    flex/sdk/trunk/modules/swfutils/src/java/flash/swf/builder/tags/DefineBitsLosslessBuilder .java
    flex/sdk/trunk/modules/swfutils/src/java/flash/swf/tools/AbcPrinter.java
    flex/sdk/trunk/modules/swfutils/src/java/flash/swf/tools/Disassembler.java
    flex/sdk/trunk/modules/swfutils/src/java/flash/swf/tools/SyntaxTreeDumper.java
    flex/sdk/trunk/modules/swfutils/src/java/flash/util/StringUtils.java

    If you're still using Buckminster 3.6, I strongly suggest switching to 3.7 - it has a number of bug fixes and improvements. This applies to both headless, and the IDE (assuming Eclipse 3.7 Indigo).
    Matthew

  • Any way to search for casts in java source code?

    Anyone know of a decent way to search your java source files to find all the casts?
    I ended up doing a simple text search for
         " = ("(quote marks not included) which works for my code because I am strict about writing my casts with spaces like
         String s = (String) iterator.next();Unfortunately, the above search has all kinds of problems with both false positives and negatives. It picks up lots of irrelevant lines like
         int index = (number > 0) ? 0 : 1;as well as misses casts that appear nested inside expressions like
         ((String) iter.next()).charAt(...)I suppose that one could do a regular expression search for any pair of open and close parens which bound non-blank text, but that would pick up even more non-cast expressions in typical java code.
    I think that the only way to properly do this is to have a tool which understands java syntax.
    Anyone know of an IDE which will do this? Does IntelliJ or Netbeans support this kind of search?
    In case you are wondering why I am interested in this, it is because I am refactoring some code to fully use generics, and searching for casts is one source of identifying candidates for genericity.

    cliffblob wrote:
    Better late than never?Yes!
    cliffblob wrote:
    ...The answer I found to ID unnecessary casts was, using Eclipse IDE, In compiler error and warning preferences to warn on unnecessary casts.Thanks for pointing IDEs out. I just opened IntelliJ, and going back to at least version 7.04 (maybe earlier) they have an inspection for "Redundant type cast".
    cliffblob wrote:
    I would still be interested to know if there is a way to identify casts in general in your source, perhaps now four years later there is a way?The only solutions that I can think of are either a complicated regex search, or you must use some tool like an IDE that understand Java syntax and can determine if a cast is happening.

  • Issue with Subtyping and Autoboxing

    Hi,
    I have a problem with subtyping and autoboxing. Can anybody please help me to know the reason for this.
    public class GenericSubType<T extends Integer> {
        T iVal;
        public GenericSubType(T t){
            iVal = t;
        public static void main(String args[]) {
            GenericSubType<Integer> gst = new GenericSubType<Integer>(30);
            System.out.println("gst.iVal = " + gst.iVal);
    The above code is giving a compile time error saying that:
    GenericSubType.java:8: cannot find symbol
    symbol : method valueOf(int)
    location : bound of type variable T
    GenericSubType<Integer>gst = new GenericSubType<Integer>(30);
    Fatal Error: Unable to find method valueOf
    If we change <T extends Integer> to <T extends Number> in the class declaration the compile time error will be resolved and the program works as expected.
    class GenericSubType<T extends Number> {
      // Body of the class...
    }Can anybody tell what is the problem with the original code and how it is affecting?
    Expecting a justifiable reason.
    Regards,
    Thomas.

    Why shouldn't I compile unnecessary statements? You only would see a warning on unnecessary cast here ;)
    The OP instead is introducing a generic parameter having a final class as bound, which pointless as for any instance the generic argument could be nothing but that very class. Why would anyone need it?
    I'm quite sure it's a javac bug (or maybe optimization issue in javac) in the combined play of autoboxing and generics. I'd say it tries to autobox the int into a T without taking into account that T always is Integer. But T obviously has no valueOf(int) method.

  • Casting parent class to a child class

    Hi,
    I have a static method which returns a class called parent. Now I want to cast it it's child class. There are no compilation errors, but at runtime it's throwing me ClassCastException. This is what I'm doing.
    public Parent getObject() {
    Parent p = new Parent();
    return p;
    Child c = (Child) getObject();What is wrong with this code? I couldn't figure it out.
    Any help will be appreciated.
    Thanks,

    Parent p1 = new Parent(); // 1
    Parent p2 = new Child(); // 2
    Child c1 = new Parent(); // 3
    Child c2 = new Child(); // 4
    Parent p1 = (Parent)c1; // 5
    Parnet p2 = (Parent)c2; // 6
    Child c3 = (Child)p1; // 7
    Child c4 = (Child)p2; // 81: Ok.
    2: Ok. Every Child IS-A parent.
    3: Compile time error. A Parent object is not a Child.
    4: Ok.
    5: Ok, because every Child IS-A parent, and the cast is unnecessary. (Though since 3 is illegal a compile time we wouldn't actually have this situation.)
    6: Ok, and the cast is unnecessary, because every Child IS-A Parent.
    7: ClassCastException at runtime. The object is not a Child.
    8: Ok.

  • Unnecessary narrowing

    Hello,
    I [more than once] stumbled accross code such as:
    Object homeRef = namingcontext.lookup("some.jndi.path.for.XxxHome");
    XxxHome xHome = (XxxHome)javax.rmi.PortableRemoteObject.narrow(homeRef, XxxHome.class);
    Xxx remoteRef = (Xxx)javax.rmi.PortableRemoteObject.narrow(xHome.create(), Xxx.class);The second cast and narrowing seem unnecessary to me. I think it's an overlooking from the developper's part which switched from Java to J2EE recently.
    But as I am recent myself to J2EE, I have still a doubt : is there any reason why one would want to do this?

    jduprez,
    Both casting and narrowing are necessary... coz of the following points,
    1. When u narrow a home object it is enabling the object to function under the Distributed environment.. not acutally down casting the object... the down casting happens by the standard java casting code that we usally write.
    In fact i have noticed in Weblogic 8.1 that u can downcast the home object and start using it with out running the object through the narrow method. What weblogic does does in this case is i GUESS is it switches off the distributed functionality of the object.
    This Concept is clearly explained in the book Mastering Enterprise Java Beans Edit II by Ed Roman. In the Corba Appendix chapter u may want to read it to totally understand why one has to run the home object through narrow method and as well as down cast.
    Hope i could clear you curiousity.
    Cheers,
    Max

  • WB tool values w/ a color cast?

    First a bit of background so you know where I'm wandering in from...
    I noticed that LR 3.3 fixed a bug with the WB tool values.  Since my partner and I had just been discussing WB adjustments on some of our images, it was interesting to see the bugfix. I've also been doing a lot of reading lately (Briot, Kuyper, among others) and WB has come into those readings as well.
    As I understand it from Briot's writings, our RAW images really are like a single channel of numbers representing color. We use LR or ACR to convert that single group of numbers to actual color channels (RGB for example).  Because of this, it's best to address any color balancing during that conversion when it's a single set of numbers (single "channel") versus 3 sets (RGB channels).  This makes sense.
    When I'm in LR doing WB I use the WB tool. But how I use it is not necessarily "correct" or "as intended."  My understanding is that using the tool, I should choose a 'neutral' within my image -- something without a color cast. At one point I tried to do this by matching the RGB percentage numbers as closely as possible -- first looking for a good neutral candidate area in the photo, then hunting within the area for the 'best' match. This works fine, but I found it a bit tedious. So, thinking of the desired WB target as being 'without a color cast', I went instead for a spot which I knew to be (or wanted to be) somewhere along the 'spectrum' from black-to-white (i.e. no "color" cast) since not all photos have a neutral gray. Some of these points might have been specular highlights -- in water for example -- though in these cases I now know I should be double checking my histogram to ensure I'm not pushing an RGB channel to the clipping point (if I have clipped a color -- i need to choose a different WB area)*.
    So, the question comes in what happens with those RAW image values (the 'single channel' numbers) when they're displayed in the WB tool?
    I'm assuming these values are produced by doing a 'calculation' to determine what % of RGB a particular value represents.  If that's the case, it would properly (hopefully) determine the RGB % values when there is proper WB in the RAW image. However, when I've got a color cast wouldn't the % values be skewed by the color cast? If not, why not?
    I suppose most find these details unnecessary in working on their images, but I find it helpful in visualizing what is really going on 'under the covers' of the tools we use to optimize our images.
    Thanks for any insight!
    - Bonnie
    * If the spectral highlight value has in effect 'no color' does this mean the single channel number has no data to differentiate the RGB % values (it sees them as 100% R, 100% G, 100% B) and therefore would indicate these values would be equal even though elsewhere in the image, there may still be a color cast? If so, why do I see decent WB results (desired color balance) if I choose one as the WB selection? Am I just getting lucky?
    If I were to choose a completely black area in the image (if that were possible to pinpoint) would it also mean there could be channel clipping on the low-end (0% R, 0% G, 0% B)?

    Thanks for the responses.
    Perhaps the most pertinent word has been "after" in terms of when the WB values will display as R=G=B. That is, "after" I have made my choice of 'neutral' within the image w/ the WB tool it will *become* neutral.
    It seems then that the values of the RGB in the WB tool are simply the result of the RAW converter's algorithm to change the single channel RAW data to R-G-B values and it's determination of what those % values currently are. So these displayed WB tool RGB values can't really be used to determine the location of a neutral color as I had earlier thought. That choice must come from the photographer's knowledge of the image and his/her choice of a desired 'neutral'.
    I realize most will simply not find it necessary to know, however I still wonder how the actual data values of the RAW are converted to the RGB channels -- but that's a question for another day.
    Thanks again.
    Happy imaging...
    - Bonnie

  • Searching for unnecessary typecasts

    Are there any tools that can read my code and find unnecessary typecasts?
    I'm in the process of upgrading all my code to use generics. I'm very pleased at the number of typecasts I'm eliminating. Since I'm doing it manually, though, I bet I'm leaving in a lot of unnecessary (and potentially unsafe) casts. It would be great to have to tool that would find all these.

    You're asking if the compiler will complain when I
    make a necessary cast? Of course not.In 1.5, don't you get a warning about an unsafe cast?
    The only time it wouldn't do that in 1.5 is if you
    didn't really need the cast, right? Maybe, I'm
    missing something.Ooops. Let me try that again...
    I see. You 're talking about unsafe casts. I'm talking unnecessary. I've got tons of code that does something like this:
            ArrayList colors;
            return (Color) colors.get(0); // Casts from Object to Color.In moving to 1.5 I'm making the container generic.
            ArrayList<Color> colors;
            return (Color) colors.get(0); // Casts from Color to Color.  Unneeded. I wanted these compiler warnings to be tell me that the cast there is unnecessary and should be removed.
            ArrayList<Color> colors;
            return colors.get(0); // No cast. Joy.

  • Polymorphism and casting

    Hi there, I would be grateful if I could get some help on the following:
    I am writing an application that dynamically processes diferent shapes (e.g. line, circle, rectangle) using a number of algorithms (algorithmA, algorithmB, algorithmC etc).
    Therefore, I have defined an abstract superclass called Shape and the subclasses Line, Circle, and Rectangle. I have also difined an abstract superclass called ShapeProcessor and a number of subclasses, ShapeProcessorA, ShapeProcessorB, ShapeProcessorC... Each shapeProcesssor class has overloaded member methods (called processShape) to process each shape type. So my ShapeProcessor class looks like:
    public abstract class ShapeProcessor{
         public abstract void processShape(Line aLine);
         public abstract void processShape(Circle aCircle);
         public abstract void processShape(Rectangle aRectangle);
    For instance, if I want to process a cirlce using the algorithm B I can write something like:
    ShapeProcessor aShapeProcessor= new ShapeProcessorB();
    aShapeProcessor.processShape(new Circle());
    My problem is when I have an array of Shape objects which I need to process. Before I can pass each shape to the processShape method I need to cast it first (i.e. to convert them from the abstract superclass Shape into a particular shape, Circle, Rectangle etc).
    A crude way of doing that it will be to retrieve the "Class" of each shape and use a switch statement to cast each shape. However, this is not what Object-Orientation is all about. Is there any better approach?
    best regards,
    Kyri.

    If you make the superclass method definition abstract,
    then once again you get the benefit of compile-time
    checking, no matter how many classes you add.I'm not sure I understand what you mean by this.
    Let's take mattbunch's approach, where a ProcessableShape calls a method in ShapeProcessor. If I understand what you're saying, you would have that method be abstract. We could also define ShapeProcessor as an interface, like so:
        public interface ShapeProcessor
            void processShape(Line shape);
            void processShape(Circle shape);
            void processShape(Ellipse shape);
        }OK, here we have our "case" statement, represented by separate methods in the interface. The ProcessableShape subclass calls processShape, passing itself as the argument, and the compiler picks the appropriate method. Each implementation of ShapeProcessor needs to implement all the methods for defined by the interface.
    The problem comes when you change the definition of ShapeProcessor but don't recompile all your implementations. This is pretty easy to do with javac, because there isn't necessarily a direct dependency. You can of course overcome the problem with a rigorous build process.
    However, if your builds do get out of sync, your app is going to blow up. Perhaps not right away, perhaps not until you happen to process the unsupported shape. But because Java does dynamic, as-needed binding, the possibility will be there.
    This isn't a Java-specific problem. I suspect that it would happen with DLLs, and know that it happens with UNIX shared libraries. The key to avoiding it is to eliminate unnecessary interdependencies, especially (in my experience) between work and worker objects.
    And, to head off the obvious critique: yes, there are times that you can't avoid such dependencies. I suspect the OP's original design was one of those times. But if by changing the design slightly, the dependencies could be eliminated, you have a better design.

  • Cast Class to some interface

    Suppose, i have an
    Object obj;
    then i can cast it to any interface an� invoke any instance methods/
    but if i have
    Class myClass = obj.getClass()...
    and i now in advance that this class implements some static method of some interface
    how can i cast a Class instance?
    something like that
    ((MyInterface)myClass).some_static_method
    ???

    well, how can i directly invoke static method,
    if i use dynamic loading??Dynamic loading is not a good mechanism for bringing in static methods. If the loaded classes are yours and you can still change the design, the "canonical" way would be to make the method non-static and provide a default instance (or even a singleton) in a static variable (presumably in the base class that is not loaded dynamically) that gets initialized when loading the subclass. This works fine if your program uses that one subclass throughout its lifetime and the only reason to load it dynamically was that the reference to the class should not be hardcoded.
    If you have several subclasses at the same time, then your problem would be how to know when to call this subclass and when that one. Once you know that, you will also have a way to know which instance to call - assuming that you create an instance of each subclass as it is loaded to provide the non-static method. Maybe you would provide the instances in a HashMap or whatever...
    If you use reflection you can also call a static method in a non-hardcoded way. This is more cumbersome to code and perhaps slower in speed. Since you have no instance, you will need to query the class by name (unless you have direct access to the loaded java.lang.Class), i.e. you will have to know its fully qualified classname.
    Class myClass = myClassLoader.loadClass("some_class");
    then, i know, that this class extends abstract class
    with some static methods
    and now, i want something like this
    ((MyAbstractClass)myClass).method1();
    of course, i could do the following
    Object obj = myClass.newInstance();only if it has a default constructor!
    ((MyAbstractClass)obj).method1()But this is the same as:
    MyAbstractClass.method1();
    I.e. you would call the static method in MyAbstractClass, NOT in a (perhaps dynamically loaded) subclass!
    This is true because for static methods no dynamic (i.e. runtime) binding takes place.
    In other words: There is no true polymorphism for static methods. For polymorphism with dynamic binding you need objects. For static methods you need no objects and never should create objects for invocation because that is not only unnecessary but suggests dynamic binding would occur - which is a wrong suggest.
    but i don't want to do so, because i use static methods
    only and thus do not need an object to create !!!
    is there a method to do soOnly when you know the classname or the java.lang.Class somehow and are using reflection as described in more detail in an earlier message in this thread. Otherwise - i.e. if you need true polymorphism with dynamic binding - you would have to use non-static methods and provide some objects to call the method on them.

  • Casting JTree to JScrollPane

    Hi,
    Is this a reasonable thing to do? I'm debugging some code for a friend. The code was written by a third party who shall remain nameless. It reads a text file into a JTree structure and the casts it to a JScrollPane using "JScrollPane sp = (JScrollPane)srcList.getParent().getParent();". Is this reasonable?
    Secondly, in trying to debug this I'm trying to follow the execution thread into the JScrollPane object, however Eclipse reports that the line number is unavaiable, this to me looks like a version of the library with no debugging/symbol info but I can't find details of a version with debugging/symbol info.
    Apologies if these are dim questions, I'm still learning... I'm a masochist, I find debugging someone elses code is often the quickest way to learn a new programming language :-)
    Many thanks for any input anyone can give! I'm desperate on this.
    Cheers,
    Brian

    It is difficult to say what is reasonable without looking at the source code, but I consider it very unlikely that a sensibly designed program would guarantee that a JTree's parent's parent is always a JScrollPane. There are bound to be maintainability and reusability issues with implicit conditions like that.
    While Swing is not bug-free, I'd also guess that it is unnecessary for you to step through any JScrollPane code to find the bug you are looking for. Can you give a slightly more concrete example of what you're trying to diagnose?
    Some more information on debugging in the JRE applicable to Eclipse:
    http://developer.java.sun.com/developer/bugParade/bugs/4652184.html

  • Error in cast a variable

    these are few lines from my long STORED PROCEDURE actually i am new to oracle 11g please
    declare
    v_s nvarchar2(10);
    p_RN nvarchar2(10);
    begin
    v_s := v_s || cast(p_RN as nvarchar2(10)); - ERROR IS COMING IN THIS LINE
    end;
    error
    ORA-06550: line 5, column 39:
    PLS-00103: Encountered the symbol "(" when expecting one of the following:
    06550. 00000 - "line %s, column %s:\n%s"
    *Cause:    Usually a PL/SQL compilation error.
    *Action:
    please somebody help me

    Just a little explanation about the error message.
    ORA-06550: line 5, column 39:
    PLS-00103: Encountered the symbol "(" when expecting one of the following:
    Line 5 column 39 is the starting parenthesis of the "(10)". For using cast you can't add a lenght to the datatype.
    If you change that, then you get a different error message:
    declare
    v_s nvarchar2(10);
    p_RN varchar2(10);
    begin
      v_s := v_s || cast(p_RN as nvarchar2); -- ERROR IS COMING IN THIS LINE
    end;
    Fehler beim Start in Zeile 13 in Befehl:
    declare
    v_s nvarchar2(10);
    p_RN varchar2(10);
    begin
      v_s := v_s || cast(p_RN as nvarchar2); -- ERROR IS COMING IN THIS LINE
    end;
    Fehlerbericht:
    ORA-06550: line 5, column 22:
    PLS-00382: expression is of wrong type
    ORA-06550: line 5, column 3:
    PL/SQL: Statement ignored
    06550. 00000 -  "line %s, column %s:\n%s"
    *Cause:    Usually a PL/SQL compilation error.
    *Action:ORA-06550: line 5, column 22:
    PLS-00382: expression is of wrong type
    This shows that you can't convert/cast a nvarchzar type into another nvarchar type.
    It would work if you cast a number into a varchar2 type for example
    declare
    v_s nvarchar2(10);
    p_RN number(10);
    begin
      v_s := v_s || cast(p_RN as nvarchar2); -- ERROR IS COMING IN THIS LINE
    end;
    anonymer Block abgeschlossen.

  • Error in cast multiset in collections

    DECLARE
    TYPE emp_dept_rec IS RECORD (
    v_sal emp.sal%TYPE,
    v_name emp.ename%TYPE,
    v_deptname dept.DEPTNAME%type
    TYPE emp_dept_tab_type IS TABLE OF emp_dept_rec;
    l_emp_dept_tab emp_dept_tab_type;
    type emp_tab is table of emp%rowtype;
    type l_emp_tab is table of emp%rowtype;
    type dept_tab is table of dept%rowtype;
    type l_dept_tab is table of dept%rowtype;
    cursor e1 is
    select * from emp;
    cursor d1 is select * from dept;
    begin
    OPEN e1;
    FETCH e1
    BULK COLLECT INTO l_emp_tab;
    open d1;
    FETCH d1
    BULK COLLECT INTO l_dept_tab;
    select cast(multiset (select em.sal,em,ename ,dep.DEPTNAME
    from table(l_emp_tab) em,table(l_dept_tab) dep
    where em.deptno=dep.deptno)
    as emp_dept_tab_type)
    into l_emp_dept_tab ;
    end;
    it is giving error as
    ORA-06550: line 43, column 25:
    PL/SQL: ORA-00923: FROM keyword not found where expected
    ORA-06550: line 39, column 5:
    PL/SQL: SQL Statement ignored

    Here is an example.
    SQL> CREATE OR REPLACE TYPE emp_rec IS OBJECT (
      2                      v_sal    NUMBER(7,2),
      3                      v_name   VARCHAR2(35),
      4                      v_empno  NUMBER(4),
      5                      v_deptno NUMBER(2)
      6                      )
      7  ;
      8  /
    Type created.
    SQL> CREATE OR REPLACE TYPE emp_tab IS TABLE OF emp_rec;
      2  /
    Type created.
    SQL> CREATE OR REPLACE TYPE dept_rec IS OBJECT (
      2                      v_deptno NUMBER,
      3                      v_dname VARCHAR2(50)
      4                      )
      5  ;
      6  /
    Type created.
    SQL> CREATE OR REPLACE TYPE dept_tab IS TABLE OF dept_rec;
      2  /
    Type created.
    SQL> CREATE OR REPLACE TYPE emp_dept_rec IS
      2                     OBJECT (
      3                      v_sal     NUMBER,
      4                      v_name     VARCHAR2(35),
      5                      v_deptname VARCHAR2(30)
      6                      );
      7  /
    Type created.
    SQL> CREATE OR REPLACE TYPE emp_dept_tab_type IS TABLE OF emp_dept_rec;
      2  /
    Type created.
    SQL> set serverout on
    SQL> DECLARE
      2    l_emp_dept_tab emp_dept_tab_type; --emp_dept_tab_type declared in database
      3    l_emp_tab      emp_tab; --emp_tab declared in database
      4    l_dept_tab     dept_tab; --dept_tab declared in database
      5 
      6    CURSOR e1 IS
      7      SELECT emp_rec(sal, ename, empno, deptno) FROM emp; --Note the type casting here
      8 
      9    CURSOR d1 IS
    10      SELECT dept_rec(deptno, dname) FROM dept; --Note the type casting here
    11  BEGIN
    12    OPEN e1;
    13 
    14    FETCH e1 BULK COLLECT
    15      INTO l_emp_tab;
    16 
    17    OPEN d1;
    18 
    19    FETCH d1 BULK COLLECT
    20      INTO l_dept_tab;
    21 
    22    SELECT CAST(MULTISET (SELECT em.v_sal, em.v_name, dep.v_dname
    23                   FROM TABLE(l_emp_tab) em, TABLE(l_dept_tab) dep
    24                  WHERE em.v_deptno = dep.v_deptno) AS emp_dept_tab_type)
    25      INTO l_emp_dept_tab
    26      FROM DUAL;
    27    FOR i IN 1 .. l_emp_dept_tab.COUNT LOOP
    28      dbms_output.put_line(l_emp_dept_tab(i)
    29                           .v_sal || '--' || l_emp_dept_tab(i)
    30                           .v_name || '--' || l_emp_dept_tab(i).v_deptname);
    31    END LOOP;
    32 
    33  END;
    34  /
    1300--MILLER--ACCOUNTING
    5000--KING--ACCOUNTING
    2450--CLARK--ACCOUNTING
    3000--FORD--RESEARCH
    1100--ADAMS--RESEARCH
    3000--SCOTT--RESEARCH
    2975--JONES--RESEARCH
    800--SMITH--RESEARCH
    950--JAMES--SALES
    1500--TURNER--SALES
    2850--BLAKE--SALES
    1250--MARTIN--SALES
    1250--WARD--SALES
    1600--ALLEN--SALES
    PL/SQL procedure successfully completed.It is just for educational purpose, because the thing you have achieved by so much programming can be done easily by simple join in the table itself.
    user10447332 Newbie
    Handle: user10447332
    Status Level: Newbie
    Registered: Oct 20, 2008
    Total Posts: 227
    Total Questions: 153 (152 unresolved) >
    What a record! and most of the time you don't care to follow/revisit the thread also!.

Maybe you are looking for

  • HP Officejet Pro 8500A Plus and Windows 8

    Hi all ~ Can anyone tell us what this means and walk us through a fix?  (You'll know from the question what our level of expertise is....) We've had an HP Office Pro 8500A Plus for a couple of years.  We just got HP TouchSmart with Windows 8 and whil

  • Cheap alternative to Apple World Travel Adapter Kit?

    The Lenmar World Travel Adapter Plug Set is only $8.64 on Amazon: http://www.amazon.com/Lenmar-AC5-World-Travel-Adapter/dp/B00013BL18/ref=wlit_dpo?ie=UTF8&coliid=IYUGMO3LZMVRI&colid=32VC09BIR8RXB Will this work? Thanks!

  • Sorting of Sum Totals at category & sub category levels in Answers

    I have a requirement where i need to sort by $$ within a category and sub category, first i need to show the highest YTD $$ under the category with total & the sub categories also should be sort as given in the example, GM having the highest value is

  • G/L Balance Table

    Hi experts, May I know what is the table with all the G/L Closing Balance. I try to look at the FAGLFLEXT but it more seems like G/L Transactional table, rather than showing the balance. Do I need to total up all the figure of previous year to get th

  • Download Oracle Developer Suite 10g (10.1.2.0.2) for Microsoft Windows

    Hi I unable to download Oracle Developer Suite 10g (10.1.2.0.2) for Microsoft Windows from the OTN website. The download starts from here: http://www.oracle.com/technology/software/products/ids/htdocs/101202winsoft.html There are two files. The secon