How can a genericized class determine its own generic type?

Hi, I have a generecized class:
class Foo<T> {
    public Class myClass() {
       // basically want to return T.class
}Is there a way to do this?
What if Foo implements FooIF, which is also paramterized with T, can I then use this.getClass().getGenericInterfaces() to find ParametrizedType and cast it to class?
Thanks,
Konstantin

Hi, I have a generecized class:
Is there a way to do this?
class Foo<T> {
    private Class<T> myClass;
    public Foo(Class<T> t){
         myClass=t;
}>
What if Foo implements FooIF, which is also
paramterized with T, can I then use
this.getClass().getGenericInterfaces() to find
ParametrizedType and cast it to class?If you do class Foo<T> implements FooIF<String> then you can get String back (but you don't cast ParametrizedType), otherwise that will just give you "T".

Similar Messages

  • How can my java application get its own PID?

    My java application runs under AIX?
    The application needs to get its own PID.
    There is a possibility to get it by
    Runtime.exec("ps -ef | grep <user.name>");
    But is there any other alternate possibility?
    Any idea would be great appreciated
    kind regards

    Hello! I found several ways for this in a blog from someone called Igor Minar on
    http://net3x.blogspot.com/2007/03/how-java-application-can-discover-its.html
    He found several ways:
    * Use Java management and monitoring API
    ManagementFactory.getRuntimeMXBean().getName();returns something like
    1826@localhost
    where 1826 is the PID of the JVM process, i.e. my application's process. But this hack is JVM dependent and may not work on JVM's other than Sun's
    * Use a shell script to put a property in place that is set to the PID:
    exec java -Dpid=$$ -jar myapp.jar* Java Native Interface - cumbersome and platform dependent solution
    * Use procfs (Linux solution: read /proc/self, nifty nifty, posted in the comments of the resp. post!)
    int pid = Integer.parseInt( ( new File("/proc/self")).getCanonicalFile().getName() );* From another comment: Reflection will work (on Unix): The Process class has a field called pid which can be queried:
    static int getPID(Process process) throws IllegalAccessException, IllegalArgumentException,
                                                                      NoSuchFieldException, SecurityException
         Field field = process.getClass().getDeclaredField("pid");
         field.setAccessible(true);
         return field.getInt(process);
    }But this solution looks a bit of a kludge to me. I think the /proc/self solution is best - it definitely rox my sox!
    Hope this helps!

  • How to create a window with its own window border other than the local system window border?

    How to create a window with its own window border other than the local system window border?
    For example, a border: a black line with a width 1 and then a transparent line with a width 5. Further inner, it is the content pane.
    In JavaSE, there seems to have the paintComponent() method for the JFrame to realize the effect.

    Not sure why your code is doing that. I usually use an ObjectProperty<Point2D> to hold the initial coordinates of the mouse press, and set it to null on a mouse release. That seems to avoid the dragging being confused by mouse interaction with other nodes.
    import javafx.application.Application;
    import javafx.application.Platform;
    import javafx.beans.property.ObjectProperty;
    import javafx.beans.property.SimpleObjectProperty;
    import javafx.collections.FXCollections;
    import javafx.event.ActionEvent;
    import javafx.event.EventHandler;
    import javafx.geometry.Point2D;
    import javafx.geometry.Pos;
    import javafx.scene.Node;
    import javafx.scene.Scene;
    import javafx.scene.control.Button;
    import javafx.scene.control.ChoiceBox;
    import javafx.scene.input.MouseEvent;
    import javafx.scene.layout.AnchorPane;
    import javafx.scene.layout.StackPane;
    import javafx.scene.layout.VBox;
    import javafx.scene.paint.Color;
    import javafx.stage.Stage;
    import javafx.stage.StageStyle;
    import javafx.stage.Window;
    public class CustomBorderExample extends Application {
      @Override
      public void start(Stage primaryStage) {
      AnchorPane root = new AnchorPane();
      root.setStyle("-fx-border-color: black; -fx-border-width: 1px; ");
      enableDragging(root);
      StackPane mainContainer = new StackPane();
        AnchorPane.setTopAnchor(mainContainer, 5.0);
        AnchorPane.setLeftAnchor(mainContainer, 5.0);
        AnchorPane.setRightAnchor(mainContainer, 5.0);
        AnchorPane.setBottomAnchor(mainContainer, 5.0);
      mainContainer.setStyle("-fx-background-color: aliceblue;");
      root.getChildren().add(mainContainer);
      primaryStage.initStyle(StageStyle.TRANSPARENT);
      final ChoiceBox<String> choiceBox = new ChoiceBox<>(FXCollections.observableArrayList("Item 1", "Item 2", "Item 3"));
      final Button closeButton = new Button("Close");
      VBox vbox = new VBox(10);
      vbox.setAlignment(Pos.CENTER);
      vbox.getChildren().addAll(choiceBox, closeButton);
      mainContainer.getChildren().add(vbox);
        closeButton.setOnAction(new EventHandler<ActionEvent>() {
          @Override
          public void handle(ActionEvent event) {
            Platform.exit();
      primaryStage.setScene(new Scene(root,  300, 200, Color.TRANSPARENT));
      primaryStage.show();
      private void enableDragging(final Node n) {
       final ObjectProperty<Point2D> mouseAnchor = new SimpleObjectProperty<>(null);
       n.addEventHandler(MouseEvent.MOUSE_PRESSED, new EventHandler<MouseEvent>() {
          @Override
          public void handle(MouseEvent event) {
            mouseAnchor.set(new Point2D(event.getX(), event.getY()));
       n.addEventHandler(MouseEvent.MOUSE_RELEASED, new EventHandler<MouseEvent>() {
          @Override
          public void handle(MouseEvent event) {
            mouseAnchor.set(null);
       n.addEventHandler(MouseEvent.MOUSE_DRAGGED, new EventHandler<MouseEvent>() {
          @Override
          public void handle(MouseEvent event) {
            Point2D anchor = mouseAnchor.get();
            Scene scene = n.getScene();
            Window window = null ;
            if (scene != null) {
              window = scene.getWindow();
            if (anchor != null && window != null) {
              double deltaX = event.getX()-anchor.getX();
              double deltaY = event.getY()-anchor.getY();
              window.setX(window.getX()+deltaX);
              window.setY(window.getY()+deltaY);
      public static void main(String[] args) {
      launch(args);

  • How can I test that the ITS is setup right and working?.

    How can I test that the ITS is setup right and working?.
    At present when calling a CRM transaction (BOR object) via the Nav Bar of the Webclient IC I am getting a message box with the title of 'Message from Webpage' and the content saying 'Object expected'.
    I have re-checked the transaction launcher and navigation bar profile setting and these look okay, hence my question regarding the ITS and how we might test that its functional.
    Jason

    I assume that as I also have a call to a URL (website), which is working fine, then the ITS servicer is also working fine.
    That just leads me to know identify why my BOR object is not being called correctly.
    Within the Transaction launcher I have the following settings:
    Entries
    Launch Trans ID: ZZIC1_LT01
    Component set: ALL
    Technical details
    Description: xxxxx
    Class name: ZCL_ZZIC1_LT01
    Statefull: X
    Further Technical details
    Transaction type: BOR Transaction
    Logical system: CMDCLNT600
    BOR Object type: TSTC_UIF
    Method name: EXECUTE
    Transaction Parameters
    Parameter: Object_key
    Value: CRMD_BUS2000115
    Can anyone see any problems with these entries?.
    what's the best way to ensure that 'CRMD_BUS2000115' is a BOR object?. I can run it as a transaction.
    Jason

  • Can i purchase encore on its own?

    I am looking to make professional DVD menus to sell.
    My question is wether i can buy Adobe Encore on its own or does it only come in a bundle with other things?

    If you want to do a one time purchase instead of a subscription you may buy Premiere Pro CS6 to get the bundled Encore CS6 Creative Suite 6
    Otherwise, you may subscribe to either all of the Cloud, or just Premiere Pro, to use Encore... which stops working if you stop subscribing
    CS5-thru-CC PPro/Encore tutorial list http://forums.adobe.com/thread/1448923 will help
    The bottom section of the link above has several Adobe links, and other information, on downloading Premiere Pro CS6 and the bundled Encore CS6, and the TWO ADDED downloads for the Encore library content, to author a DVD or BluRay... and the tutorial list includes learning how to use Encore... pay particular attention to the picture in reply 3 at this link - https://forums.adobe.com/thread/1516173

  • My phone is on disable and ask me to connect to itunes and when i try it says i need to unlock my phone? how can i unlock it if its locked ?

    my phone is on disable and ask me to connect to itunes and when i try it says i need to unlock my phone? how can i unlock it if its locked ? please help?

    Connect in recovery mode according to http://support.apple.com/kb/HT1212

  • HT203176 When I delete a file, it does not appear in the Trash - How can I fix this. Its a brand new MacBook Pro 17'

    When I delete a file, it does not appear in the Trash - How can I fix this. Its a brand new MacBook Pro 17''

    http://www.thexlab.com/faqs/trash.html for starters.

  • How can i set class path in ubuntu JAVA_HOME ?

    how can i set class path in ubuntu <JAVA_HOME>?

    Note that on *nix
    environment variable names are case sensitive.
    Also, you are again being vague; is it [this it|http://java.sun.com/j2se/1.5.0/docs/tooldocs/solaris/javac.html] or [that it|http://java.sun.com/j2se/1.5.0/docs/tooldocs/solaris/java.html]

  • How can I control instrument using its RS232 port in VB or VC++?

    1)How can I control instrument using its RS232 port in VB or VC++?
    2)What's the module or .h file need I add-in to VB or VC++?
    3)Can you provide me some easy examples for that?
    Thanks!

    Kevin,
    I've used Measurement Studio - Tools for Visual Basic and Tools for Visual C++ (ActiveX component) for instrument control.
    I've used both the VISA and non VISA versions and they are pretty straight forward to use for GPIB, Serial or VXI.
    You might find the following page useful.
    http://www.ni.com/mstudio/cworks.htm#ICC
    Regards,
    Kamran

  • HT5957 how can i fix my iphone its already ios 7 then now need activation required

    how can i fix my iphone its already ios 7 then now need activation required

    Were you, by chance, running a beta version of iOS 7 on your phone?
    If so, this will be the problem. You will need to log Into the private developers forum athttps://developer.apple.com/support/ios/
    If you are not a developer, you will need to seek help by way of your favourite search site.

  • How can i add form of my own to "SAPM07DR"

    i been asked to add form develop by me to the standart program "SAPM07DR" .
    this task came from the need of the implementation
    of the "material management" , assign forms and program.
    now i get the output "ZWE4"  ,
    and i want to assign form of my own  ,
    i tried to add smart form but i get message
    "Errors occurred while processing output"
    so I want to try layout  with  standard program "SAPM07DR" .
    how can i add form of my own to this program

    First, you must copy this program to your own program with "ZSAPM07DR" then copy the include program where the routine pass through the program
    example: entry_we03 -> from include M07DRENT and M07DRAUS
             change this include to ZM07DRENT and ZM07DRAUS
    The next step is binding your form in the program.
    what forms do you use ? Sapscript or Smartforms ?
    in this Program already used Sapscript. You can See there is Open_Form Function in that Program.
    I suggest you to Bind Smartforms.
    IF you use smartforms, Remark All Statement from
    "PERFORM open_form_sammel." to "PERFORM close_form." before endform
    that perform including in M07DRAUS -> FORM lesen_wes USING objky lgortsplit.
    after that put this program to replace the remark :
    data : FMNAME type RS38L_FNAM.
    DATA: ls_control_param      TYPE ssfctrlop.
    set preview parameters
          MOVE 'X' TO ls_control_param-no_dialog.
          MOVE 'X' TO ls_control_param-preview.
          MOVE 'PRINTER'  TO ls_control_param-device.
    *break-point.
    *****Print SmartForms
      CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
            EXPORTING
              FORMNAME           = TNAPR-SFORM
            IMPORTING
              FM_NAME            = FMNAME
            EXCEPTIONS
              NO_FORM            = 1
              NO_FUNCTION_MODULE = 2
              OTHERS             = 3.
         CALL FUNCTION FMNAME
         EXPORTING
             control_parameters   = ls_control_param
         TABLES
             traptab           = traptab
         EXCEPTIONS
             formatting_error = 1
             internal_error   = 2
             send_error       = 3.
         if sy-subrc NE 0.
    *******message 'Error' type 'S'.
         endif.
    *******End Smartforms
    Hope This Help...

  • HT5622 How can i use the facetime, its appearing in the screen but i cannot use it...

    How can i use the facetime, its appearing in the screen but i cannot use it.

    http://support.apple.com/kb/ht4319

  • How can i learn class methodology

    i'm a programmer for 2 years. i know vb 6.0, php 4. but in these languages i never make a program with using class. because i dont know how can i make a class.
    now i started to learn java. but i can't understand how can i write class in my programs. or how can i extend classes...
    what will i do to learn class. what you offer...?
    thanks for your response.
    [email protected]

    Nothing is better for the learning process than farting about /being experimental /trial and erroring in Notepad and javac, eg;-class A{
       protected A(){
         System.out.print("Hello ");
    public class B extends A{
       public static void maain(String []params){
         doesThisWork();
       private B(){
         System.out.print("world");    
       public static void doesThisWork(){
          B b = new B();  // what gets printed to screen?
          A a = new A();  // what gets printed to screen?
          a = b;  // do these compile or create a runtime error?
          b = a;
          a = (a)b;
          b = (b)a;

  • My new iphone 5 is downloading 800 songs - how can i stop this as its not required as i can simply sync my phone with my mac., my new iphone 5 is downloading 800 songs - how can i stop this as its not required as i can simply sync my phone with my mac.

    my new iphone 5 is downloading 800 songs - how can i stop this as its not required as i can simply sync my phone with my mac., my new iphone 5 is downloading 800 songs - how can i stop this as its not required as i can simply sync my phone with my mac.

    thats not what i mean - the songs are all in my itunes library on the computer but if i click the itunes icon on the phone they are also trying to download here - all i need to know is how do i stop this as when i go anywhere without broadband its eating my data allowance!!!!

  • My ipad and iphone keep losing the connection to email. It was fixed once at the Apple store. How can I fix it on my own?

    My iphone and ipad keep losing email function. It was fixed once at the Apple Store. Now it has happened again. How can I fix this on my own?

    Really??? The two options are 'solved my problem' and 'this helped me'.
    How about...NONE OF THE ABOVE!

Maybe you are looking for