How to use classloader in this way? Is it possible?

I have one my own classlaod. So, I can do these: use the classloader to load the class, use the class's newInstance method to get instance object, then use reflection to invoke methods of the object.
I think this is the standard way.
However, it is not convenient. Is there a way that allows me to using the class that loaded by my own classload in "old way", i.e. just new to get object, and directly use it. For example, like this:
..Get classloader
class MyClass = loadClass("MyClass");
MyClass obj = new MyClass();
obj.someMethod();
If this way is possible, it is much better. In theory, it should have no problem. I think Java Web Start, etc are just doing similar like this. But, at this point, I do not know. Please share your thoughts.

You have to distinguish between compile time, and run time features available to you.
MyClass x = new MyClass() ; is a language construct that is available at compile time.
Reflection is available at runtime.
If you want a mix of both, you may have to generate code. Depending on how you like it - you can either generate source and compile it, or generate byte code directly. But since you seem to be interested more in simplifying your code, due to the relative obscurity of reflective code, your best option would be to use a code generator.
So use your classloader to load the class, then generate and compile code to use it. (This may be even more complex, but this is how you would have to do it)

Similar Messages

  • HOW TO use DBDataSource in this situation?

    hi all,
      I add a Matrix on system Form(eg:BOM Form),then I want to use Matrix.LoadFromDataSource() to load data.
    the simple code is :
    SAPbobsCOM.Recordset oRecordset = (SAPbobsCOM.Recordset)SBO_Company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset);
                oRecordset.DoQuery("select ItemCode,ItemName from OITM ");
                SAPbouiCOM.Matrix oMatrix = (SAPbouiCOM.Matrix)m_SboForm.Items.Item("MatrixFormUID").Specific;
                    SAPbouiCOM.DBDataSource oDBData = m_SboForm.DataSources.DBDataSources.Item("tablename");//this dbdatasource is added before
                    oDBData.Clear();//error occur in this code:Operation is not supported in system Form
                    oRecordset.MoveFirst();
                    while (!oRecordset.EoF)
    oMatrix.LoadFromDataSource();
    how to use LoadFromDataSource() in this situation?if evaluate every control,the speed is too slow.
    thanks

    The quick way is as I wrote you - bind it to datasource (you fill it cell by cell). The code is something like:
    omatrix.Clear()
    oColumn = oColumns.Item("Column name 1")
    oColumn.DataBind.SetBound(True, "table name", "itemcode")
    oColumn = oColumns.Item("Column name 2")
    oColumn.DataBind.SetBound(True, "table name", "itemname")
    oMatrix.LoadFromDataSource();
    There isn`t necessary the while (!oRecordset.EoF) cycle

  • How to use two split this method in my code

    How to use two split this method in my code
    if i got one string line which like this
    ("aa!bb!cc~ab!bc!cd") a
    nd want to use two split to spare ! and ~ this seal for my spare point how that output
    has come diff ?
    public static void main(String[] args) {
        String str = "aa!bb!cc~ab!bc!cd";
        String strs[]= str.split("~");
        String strE[]= str.split("!");
        int count =0;
        for(int j=0; j < strs.length; j++){
          for (int i = 0; i < strE.length; i++){   
              System.out.println(count + " " + strE);
    count++;
    the output how can it be like this
    0 aa
    0 bb
    0 cc
    1 ab
    1 bc
    1 cd

    Move your second slit inside the first loop, so you are splitting the substring, not the entire string.

  • Freaking OUT!! I have a desktop (IMac) and my IPhoto library is gone! Events gone, albums gone, faces gone!!! I can't even find the folder for IPhoto Library under Pictures under my hardrive. I have no idea how long it's been this way!

    Ok so here's what has happened. I got on the Mac to open IPhoto. It opened, but no files PERIOD! No albums, events, photos, faces. They were all empty. I had TONS of albums and photos. I have no clue how long it's been this way, probably a couple of weeks since I've been on it. Ac couple of things come to mind that might have caused or had something to do with...IPhone 4 had to be restored and a back-up and upgrade occurred. Also, I deleted files off my camera while connected. Not sure the culprit, but VERY UPSET! I have never set up Time Machine and have no other back up. I downloaded and purchased File Salvage but I have to get an external hard drive before it will do it. I put the application install CD in last night thinking that if I reinstalled it would help but then I got scared and shut Mac down half way through. I couldn't even find the file IPhoto Library. When I open IPhoto it say IPhoto 9 but when I "get more info" it says IPhoto 8.1.2 or something like that. Please HELP!!

    Try an All Images Search:
    In the Finder:
    Command - f
    Kind: Images
    Size: Greater than 300kb (This is to avoid all the thumbnails, icons and so on.)
    Set it to search the Mac.
    As to why? The most likely answer is user error, I'm afriad. It does point up the importantce of always having a back up.
    Regards
    TD

  • Javascript error on - Help - Learn how to use Numbers with this online...

    I am trying to find out more about Numbers. I am using iTunes 9.1.1 on a Vista PC. I get a Javascript error in Internet Explorer 8 when I try to access:
    Help - Learn how to use Numbers with this online resource.
    http://help.apple.com/numbers/1.0
    The link redirects to the following page:
    http://help.apple.com/iwork/safari/interface/#tan727163ed
    The above page is blank except for boxes for Keynote Help, Pages Help, Numbers help, and a blank input field that seems to do nothing. Here is the Javascript error message from Internet Explorer 8:
    Webpage error details
    User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.5.30729; .NET CLR 3.0.30729)
    Timestamp: Tue, 1 Jun 2010 20:55:54 UTC
    Message: This command is not supported.
    Line: 1
    Char: 41589
    Code: 0
    URI: http://help.apple.com/iwork/safari/interface/javascript.js

    Link also does not work for me in WIN 7 with IE8. However, it does work in Chrome in WIN 7. It also works in Safari on my G4. Suggest you try Chrome or it may work in another browser like FireFox or Safari in Vista.

  • What do you think about using plant in this way?

    In your systems each plant is "real" - has real location and real manager, or also you have “virtual” plants to monitor a particular special process (for example: if you want different FI bookings for the same material movement type, or if you want to track special kinds of stock)?
    What do you think about using plant in this way?

    Hello Friend,
    It is surely a good step from FI point off view but creating something virtual and transacting on it, from MM point of view is not feasible as it is difficult to frame the scenario and work on it.
    Rest is your decision.
    Regards,
    Pradnyesh Naik

  • Firefox comes up in "safe" mode. How do I turn it off. I can't use the program this way.

    About two weeks ago some virus (?) got in my computer. I lost everything and had to reload everything.
    When I reloaded Firefox it came up 'locked'. Nothing would react to my mouse.
    I discovered it came up in "safe" mode. I removed the program and reloaded it again. It came up in safe mode again. When I hit start and look at programs Firefox is there and under it is another Firefox program with safe mode in parenthesis. I can't use it this way. How do I turn safe mode off?

    See [[Firefox is stuck in Safe Mode]], the last option seems to be the most likely in your case.

  • Will jsp use connPool by this way?

    I installed mysql-essential-4.1.13a-win32 and jakarta-tomcat-5.0.19. I just copyed mysql-connector-java-3.1.10-bin.jar to CATALINA_HOME\common\lib and did nothing to CATALINA_HOME\conf\server.xml, WEB-INF\web.xml. Through jstl, i can access mysql db.I want to know that whether my jsp are using connection pool to access mysql by this way?

    Thanks for your replying:), I use the code below to access mysql:
    <%@ page contentType='text/html;charset=gb2312'%>
    <%@ taglib prefix='c' uri='http://java.sun.com/jsp/jstl/core'%>
    <%@ taglib prefix='sql' uri='http://java.sun.com/jsp/jstl/sql'%>
    <sql:setDataSource var='dbRef' url='jdbc:mysql://localhost:3306/demo'
                                             driver='com.mysql.jdbc.Driver' user='user' password='password'/>
    <sql:query var='queryRst' dataSource='${dbRef}'>
         SELECT * FROM employees
    </sql:query>
    <table align='center'>
         <tr>
              <c:forEach items='${queryRst.columnNames}' var='colName' begin='1'>
                   <th align='center' bgcolor='lightgrey'>${colName}</th>
              </c:forEach>
         </tr>
         <c:forEach items='${queryRst.rowsByIndex}' var='record'>
              <tr>
                   <c:forEach items='${record}' var='field' begin='1'>
                        <td>${field}</td>
                   </c:forEach>
              </tr>
         </c:forEach>
    </table>It is relly a good idea according to SoulTech2012, i don't know how to set a breakpoint in the connection pool or use whatever admin tools you have to monitor the connection pool.What references shoud i turn to on this point?
    As evnafets say, i specify all the params in jstl. So connection pool shoud not be used. Can i use connection pool without configing server.xml or web.xml?

  • How to use to_date for this case?

    Hi,
    I bind parameters in java code.
    The param type in java is Timestamp and the data type in table is date.
    Here is the sql section printted in log:
    2004-08-01 10:00:00.0 <= table.datetime
    Why there is a ".0" after second?
    And how to use to_date to convert "2004-08-01 10:00:00.0"?
    Thanks!

    Hi,
    Here are a few possibilities
    SQL> select cast(timestamp '2004-08-01 10:00:00.0' as date) from dual;
    CAST(TIMESTAMP'2004
    2004-08-01 10:00:00
    SQL> select to_date('2004-08-01 10:00:00.0','YYYY-MM-DD HH24:MI:SS".0"') from dual;
    TO_DATE('2004-08-01
    2004-08-01 10:00:00
    SQL> select to_date(substr('2004-08-01 10:00:00.0',1,19), 'YYYY-MM-DD HH24:MI:SS') from dual;
    TO_DATE(SUBSTR('200
    2004-08-01 10:00:00

  • How to get output in this way ?

    actual data is this :
    CRANE_ID CRANE_CASE SEQ desc
    C01 NORM 1 desc1
    C01 NORM 2 desc2
    C01 NORM 3 desc3
    C01 NORM 4 desc4
    C01 XX1 1 desc5
    C01 XX1 2 desc6
    C02 NORM 1 desc7
    C02 XX1 2 desc8
    C03 NORM 1 desc9
    C03 XX2 2 desc10
    how to get data in this format :
    crane_id case 1 2 3 4
    C01 NORM desc1 desc2 desc3 desc4
    C01 XX1 desc5 desc6
    C02 NORM desc7
    C02 XX1 desc8
    C03 NORM desc9
    C03 XX2 desc10
    header should contain all sequence that is maximum.

    How to group my output w.r.t one column ?
    you need to do your own homework assignments

  • How to use LIKE in this CASE?

    There are multiple values that start with "Aerospace".  All of them are going to be set to the same value.  I'm trying to write a Case Statement that will replace all of them with the new value, but i can't get the LIKE to work correctly.
      This can probably be done with REPLACE, but It's bugging me that I can't get the LIKE to work.  
    I've tried a few variations, but compiler hasn't like any of them.  I'm hoping to have one line of code that will work for all of the possible choices.
    What is the best way to use a LIKE or similar thing (such as CONTAINS) to set all of the fields with "Aerospace" at the beginning?
    Sorry for the small font above.  I didn't see how to change it.
    'New Sector Focus' = CASE sectorfocus
    WHEN sectorfocus LIKE 'Aerospace%' THEN '201010 - Aerospace & Defense'
    ELSE sectorfocus
    END

    CASE expression looks good. CASE blog: 
    http://www.sqlusa.com/bestpractices/training/scripts/casefunction/
    >Sorry for the small font above.  I didn't see how to change it.
    Use the HTML icon to edit the html code.
    Kalman Toth Database & OLAP Architect
    SQL Server 2014 Design & Programming
    New Book / Kindle: Exam 70-461 Bootcamp: Querying Microsoft SQL Server 2012

  • How to select rows in this way ?????

    Hi All,
    How to select tables from 2 table say client and vendor. Both have id, name. Now I want data of two tables using union but the data of one table come after another.
    select id,name from vsg.client union select id,name from vsg.vendor
    Eg.
    Vendor Client
    ID Name ID Name
    1 ab 12 xyz
    2 cd 13 wyx
    3 ef 14 pqr
    Now output should come like this
    ID Name
    1 ab (First rows from Vendor)
    2 cd
    3 ef
    12 xyz (second rows from Client)
    13 wyx
    14 pqr
    Thanks for your reply in advance......

    NO this one is not workingWhy not? Are you using some ancient version of Oracle?
    SQL> create table vendor
      2  as
      3  select 'v1' id, 'a' name from dual union all
      4  select 'v3', 'c' from dual union all
      5  select 'v2', 'b' from dual
      6  /
    Tabel is aangemaakt.
    SQL> create table client
      2  as
      3  select 'c1' id, 'd' name from dual union all
      4  select 'c3', 'f' from dual union all
      5  select 'c2', 'e' from dual union all
      6  select 'c4', 'g' from dual
      7  /
    Tabel is aangemaakt.
    SQL> select id
      2       , name
      3    from ( select id
      4                , name
      5                , 1 x
      6             from vendor
      7            union all
      8           select id
      9                , name
    10                , 2
    11             from client
    12         )
    13   order by x
    14       , id
    15  /
    ID N
    v1 a
    v2 b
    v3 c
    c1 d
    c2 e
    c3 f
    c4 g
    7 rijen zijn geselecteerd.Regards,
    Rob.

  • How to use threads in this script???

    Hi, I�m new to java, and I my first script is a reciprocal link checker but I have a problem with the speed. I have the next class for check a html page to search for a string (the reciprocal link). The problem is that when I pass the script more than 50 pages to check, the proccess ibs very slow. I thought that the problem is stablishing the connections, because it makes only one at a time.
    I think, that with threads the I can accelerate the proccess, but I don�t know how to implement here. If you can give some advise, very thanks in advance. Here is the class:
    import java.net.URL;
    import java.net.URLConnection;
    import java.io.BufferedReader;
    import java.io.InputStreamReader;
    class checkHtml {
    boolean comprobarReciproco(String thisUrl, String reciproco) {
    String toReturn = null;
    boolean res = false;
    try {
    URL url = new URL(thisUrl);
    URLConnection thisConn = url.openConnection();
    BufferedReader receiver = new BufferedReader(new InputStreamReader(thisConn.getInputStream()));
    String line = new String();
    // Leemos del buffer de entrada l�nea a l�nea
    while((line = receiver.readLine()) != null) {
    if (line.indexOf(reciproco) != -1 ){
    res = true;
    break;
    } catch(Exception e) {
    System.out.println("Error:" + e);
    return res;
    public static void main(String[] args){
    checkHtml x = new checkHtml();
    System.out.println(x.comprobarReciproco("http://www.somewebpage.com/blahblah.htm","reciprocal"));

    I make the call to this proccess in the main class, with this method:
    public String [][] comprobarRecip(String arr[][], String recip){
    checkHtml check = new checkHtml();
    int j=0;
    String enlacesfinal[][] = new String[tamanyoLinks(arr)][2];
    for (int i=0; i < tamanyoLinks(arr); i++){
    // Si no est� el reciproco nos guardamos el enlace en enlacesvalidos
    if (check.comprobarReciproco(arr[0],recip) == false){
    enlacesfinal[j][0] = arr[i][0];
    enlacesfinal[j][1] = arr[i][1];
    j++;
    return enlacesfinal;
    Is in this method, where I must use the threads? Thanks a lot!

  • ITunes 11 on a PC - where is Genius and how to use it in this version?

    I'm on a PC and using iTunes 11, and cannot find the bottom right hand show/hide genius toggle. There is no checkbox on PC for "enable genius" in preferences (as some on the Mac forums point out.) I'm trying to get Genius suggestions based on my songs.to discover and purchase. Apple what have you done??!? Any help appreciated.

    hi dominic.
    thanks for the help and the links.
    there is something terribly lacking in mac UI with respect to this unless i am missing something. if i do a search in Spotlight i see results and even when i see the file i want to know something about i have to OPEN FINDER which shows a ton of results (including hundreds if not thousands of eml file that i have to call mac and probably pay to find out why they are still showing up when prefs in Spotlight say to not show them...)  and only then can i actively select the file and have it show a file path at the bottom of the finder window.
    this is maddening. isn't there an option to show this information in Spotlight or to show this information WHEN THE FILE IS OPEN (apologies for the caps). i mean, if i have a file open, maybe i don't know /where/ it came from for some reason.
    for instance, if i am in a hurry and i open the file directly from Spotlight i can edit it and save it but i still have no idea where it resides on my hard drive. similarly if i open a file directly from spotlight and DUPLICATE a file and i want to save it as Version 2 - i have to - - - - well i guess i have to run another search for the file i just opened and am working upon in order to just save the dang file to the same location the original is in?
    i mean, the links are showing that i should open Get Info but i think i need to see the file in finder to run this command anyway since i have to right click on the file itself.
    maybe i am missing something but can't MAC OS just show me the FILE PATH at the top of the document like it does in Finder and also show me the FILE PATH in Spotlight? seems like the current implementation is like a big game of hopscotch for no good reason except the information is not shown to the (power) user.
    maybe i am missing a new feature in ML or in Mavericks or maybe i am using the wrong terms in the original title?
    THANK YOU

  • How to use counter in this case

    in my selection screen i have billing doc no-vbeln.
    in my ztable i have etimes a field.
    when i enter a bill doc no and press f8, my etimes feild in ztable sets to 1.
    my requirement is if i enter a bill doc as 97600654 for first time, etimes is 1.
    for second time if i enter that same bill doc i.e 97600654 , etimes should be 2 and if third then 3 and so on.
    if a new doc is entered then etimes is again 1.
    how to code this..plz provide some code.

    Hi Rudra,
    First You need to create a Ztable(say ZTT_VBELN_COUNT) with Three fields MANDT VBELN ETIMES.
    Now in your program add code as below;
    DATA wa_vbeln_count type line of ZTT_VBELN_COUNT.
    SELECT SINGLE * FROM ZTT_VBELN_COUNT INTO CORESSPONDING FIELDS OF wa_vbeln_count where VBELN = lv_vbeln.
    IF SY-SUBRC EQ 0.
       wa_vbeln_count-etimes = wa_vbeln_count-etimes + 1.
    ELSE
       wa_vbeln_count-vbeln = lv_vbeln.
       wa_vbeln_count-etimes = 1.
    ENDIF.
    MODIFY ZTT_VBELN_COUNT FROM wa_vbeln_count.
    Regards
    Karthik D

Maybe you are looking for

  • Windows Vista w/ QT: Plays M4V But Not MOV

    Any ideas where I can get a new codec driver for Vista?

  • Notification creation using imrc0001 exit(ik11) but unble to get the status

    Hai to all i had used the exit IMRC0001 for the creation of notification if reading exceeds the upper range using fm BAPI_ALM_NOTIF_CREATE BAPI_ALM_NOTIF_SAVE It is updated in table VIQMEL but when i open tcode iw22 is giving me a error message Objec

  • Database emergency startup

    We have a Oracle9i database on RHEL ver.4. After installed new storage, our disk partition was broken and database was shutdown. Question 1. When File system was broken cause of media failure, we want know how startup database by force even though we

  • Import Custom Shapes into Pages

    Hi! I am not as glad with the "onboard" shapes of pages and want to import some custom shapes (from Inkscape or Neooffice) into Pages. It's no Problem with Bitmaps. But I just can't get vector graphics to get imported into pages. Is there an easy way

  • Word document will not open on macbook pro?

    Hi- a Word document (2007- docx) will not open on my macbook pro. Any tips?