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 6690585
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:39:15+00:00 2026-05-26T05:39:15+00:00

I have a JET Template that is meant to generate code for an interface

  • 0

I have a JET Template that is meant to generate code for an interface implementation class. I am having trouble coming up with an executable test class that prints out this generated code because I am unable to get an object for the argument of the generate method created from the JET Template.

I want the test class to work something like this:

/**
 * An executable test class that prints out exemplary generator output
 * and demonstrates that the JET template does what it should.
 */
public class TestClass {
    public static void main(String args[]) throws ClassNotFoundException, InstantiationException, IllegalAccessException {

        String className = "A"; // "A" is the name of the interface in the same package.

        Class c = Class.forName(className);
        Object o = c.newInstance();

        Q2Generator g = new Q2Generator(); // Class created from the JET Template
        String result = g.generate(o);
        System.out.println(result);
    }
}

But obviously, c.newInstance(); doesn’t work for an interface. Is there another way I could possibly feed an object of the interface through to the generate method? I need the object of the interface because in the Q2Generator’s generate method, it takes information about the method declarations in the interface from the object argument.

I’m not sure if that provides enough context, but if it isn’t enough there are more details in another question I asked here: Using JET to generate code: Indenting code

Thanks.

  • 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-26T05:39:15+00:00Added an answer on May 26, 2026 at 5:39 am

    If I understand what you’re trying to do, you should be able to pull it off with dynamic proxying. Here’s an example of implementing an interface at runtime without explicitly knowing the interface’s type:

    import java.lang.reflect.*;
    
    public class ImplementInterfaceWithReflection {
        public static void main(String[] args) throws Exception {
            String interfaceName = Foo.class.getName();
            Object proxyInstance = implementInterface(interfaceName);
            Foo foo = (Foo) proxyInstance;
            System.out.println(foo.getAnInt());
            System.out.println(foo.getAString());
        }
    
        static Object implementInterface(String interfaceName)
                throws ClassNotFoundException {
            // Note that here we know nothing about the interface except its name
            Class clazz = Class.forName(interfaceName);
            return Proxy.newProxyInstance(
                clazz.getClassLoader(),
                new Class[]{clazz},
                new TrivialInvocationHandler());
        }
    
        static class TrivialInvocationHandler implements InvocationHandler {
            @Override
            public Object invoke(Object proxy, Method method, Object[] args) {
                System.out.println("Method called: " + method);
                if (method.getReturnType() == Integer.TYPE) {
                    return 42;
                } else {
                    return "I'm a string";
                }
            }
        }
    
        interface Foo {
            int getAnInt();
            String getAString();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have code that depends a relatively small MS Jet (created in Access) database.
So I have learned that that the Microsoft.Jet.OLEDB.4.0 data provider for querying data sources
I have an application that ships to the customer with a JET database including
I have the following code : string excelConnectionString = @Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\db\suc.xls; Extended Properties=Excel
I have the following code in C# Visual Studio 2010. string connectionString = Provider=Microsoft.Jet.OLEDB.4.0;Data
I have a C++ app that uses a Jet database through DAO. Large queries
I have an Access 2003 database using MS-JET linked tables (that is, there are
I have tried the code below: SELECT * INTO NewTablenNmeHere FROM OPENROWSET( 'Microsoft.Jet.OLEDB.4.0', 'Excel
I have an Access database that I am interacting with using JET with the
I have a Microsoft Access database that I connect to with the Jet Database

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.