Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6230867
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T09:49:50+00:00 2026-05-24T09:49:50+00:00

Here’s some of my code: My module contains: <generate-with class=com.bilancio.ReflectionGenerator> <when-type-assignable class=com.bilancio.client.Reflection /> </generate-with>

  • 0

Here’s some of my code:
My module contains:

<generate-with class="com.bilancio.ReflectionGenerator"> 
  <when-type-assignable class="com.bilancio.client.Reflection" /> 
</generate-with> 

public interface Constructable {} 


public interface Reflection { 
    public <T> T instantiate( String className ); 
}


public class ReflectionGenerator extends Generator 
{ 
    @Override 
    public String generate( TreeLogger logger, GeneratorContext 
context, String typeName ) throws UnableToCompleteException 
    { 
        TypeOracle oracle = context.getTypeOracle( ); 
        JClassType markerInterface = 
oracle.findType( Constructable.class.getName( ) ); 
        List<JClassType> clazzes = new ArrayList<JClassType>( ); 
        PropertyOracle propertyOracle = context.getPropertyOracle( ); 
        for ( JClassType classType : oracle.getTypes( ) ) 
        { 
            if ( !classType.equals( markerInterface ) && 
classType.isAssignableTo( markerInterface ) ) 
                clazzes.add( classType ); 
        } 
        final String genPackageName = "com.bilancio.client"; 
        final String genClassName = "ReflectionImpl"; 
        ClassSourceFileComposerFactory composer = new 
ClassSourceFileComposerFactory( genPackageName, genClassName ); 
composer.addImplementedInterface( Reflection.class.getCanonicalName( ) ); 
        composer.addImport( "com.bilancio.client.*" ); 
        PrintWriter printWriter = context.tryCreate( logger, 
genPackageName, genClassName ); 
        if ( printWriter != null ) 
        { 
            SourceWriter sourceWriter = 
composer.createSourceWriter( context, printWriter ); 
            sourceWriter.println( "ReflectionImpl( ) {" ); 
            sourceWriter.println( "}" ); 
            printFactoryMethod( clazzes, sourceWriter ); 
            sourceWriter.commit( logger ); 
        } 
        return composer.getCreatedClassName( ); 
    } 
    private void printFactoryMethod( List<JClassType> clazzes, 
SourceWriter sourceWriter ) 
    { 
        sourceWriter.println( ); 
        sourceWriter.println( "public <T> T instantiate( String 
className ) {" ); 
        for ( JClassType classType : clazzes ) 
        { 
            if ( classType.isAbstract( ) ) 
                continue; 
            sourceWriter.println( ); 
            sourceWriter.indent( ); 
            sourceWriter.println( "if( className.equals(\"" + 
classType.getName( ) + "\")) {" ); 
            sourceWriter.indent( ); 
            sourceWriter.println( "return new " + 
classType.getQualifiedSourceName( ) + "();" ); 
            sourceWriter.outdent( ); 
            sourceWriter.println( "}" ); 
            sourceWriter.outdent( ); 
            sourceWriter.println( ); 
        } 
        sourceWriter.println( ); 
        sourceWriter.outdent( ); 
        sourceWriter.println( "}" ); 
        sourceWriter.outdent( ); 
        sourceWriter.println( ); 
    } 
} 

I want to use it like that:

GWT.create(Reflection.class)).instantiate(“MyPanel”)

MyPanel class obviously implement ‘Constructable’ interface.

I keep getting:

Type mismatch: cannot convert from MyPanel to T

What do you think?

edited:

I modified this line, trying to do an unchecked cast, but still the error:

sourceWriter.println( "return (T) new " + classType.getQualifiedSourceName( ) + "();"); 

And here’s my trace:

[DEBUG] [main] - Rebinding com.bilancio.client.Reflection
    [DEBUG] [main] - Adding '1' new generated units
        [DEBUG] [main] - Validating newly compiled units
            [ERROR] [main] - Errors in 'generated://670356D9DA0D417BB8171499B4C4D57B/com/bilancio/client/ReflectionImpl.java'
                [ERROR] [main] - Line 9: This method must return a result of type T
                [INFO] [main] - See snapshot: /tmp/com.bilancio.client.ReflectionImpl6488844579312624283.java
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T09:49:50+00:00Added an answer on May 24, 2026 at 9:49 am

    Solved here: http://groups.google.com/group/google-web-toolkit/browse_thread/thread/197feee215b80533

    I was missing default return value ^_^

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is the code I'm using http://jsbin.com/evike5/edit When the jQuery UI dialog is fired
Here's some of my production code (I had to force line breaks): task =
Here is some code I made :) @echo off set source=R:\Contracts\ set destination=R:\Contracts\Sites\ ROBOCOPY
here is the scenario 1: user starts to type some word, autocomplete engine shows
Here is my code, which takes two version identifiers in the form 1, 5,
Here is my persistence.xml : <?xml version=1.0 encoding=UTF-8?> <persistence xmlns=http://java.sun.com/xml/ns/persistence xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance xsi:schemaLocation=http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd version=1.0>
here is the site : http://www.notrepanorama.com at the bottom left, i use a jquery
Here is a great article about GC may occur at unexpected point of code
Here is my javascript code for a cursor focus function to go to username
Here is my code...I have two dimensional matrices A,B. I want to develop the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.