Advertisement
Guest User

some features

a guest
May 17th, 2025
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.86 KB | Source Code | 0 0
  1.  
  2. 1.  A solution for overloading (very bad now but might improve, a keyword called "dynamic")
  3. 2.  Less verbose access to object fields and methods via the "expose" and "exposed" keywords
  4. 3.  Ways to make method and field declarations easier (like how void methods don't need `void` to be specified).
  5.  
  6. The `dynamic` keyword:
  7. Allows you to write patterns that define the possible ways a method can be called, in a set of argument names that are enclosed in square brackets to indicate that they are optional.
  8.  
  9. See these examples:
  10.  
  11. `dynamic[name, age, birthday] []` = you either specify all three arguments, or none.
  12. `dynamic[name, age, [birthday]]` = you either specify two arguments (`name`, `age`) or three arguments (`name`, `age`, `birthday`).
  13. `dynamic[name, [age], birthday] []` = you either specify none, or two arguments (`name`, `birthday`) or three arguments (`name`, `age`, `birthday`).
  14.  
  15. To be easier to use, I also plan to add default values to arguments.
  16.  
  17. Example in code:
  18.  
  19. ```java
  20. // java with overloading
  21. public void move(int plane, boolean clockwise) {
  22.    move(plane, clockwise, true);
  23. }
  24.  
  25. public void move(int plane, boolean clockwise, boolean record) {
  26.    super.move(plane, clockwise);
  27.    if (record) {
  28.        moveRecord.add(new Move(plane, clockwise));
  29.    }
  30. }
  31.  
  32. //my syntax without overloading
  33. public dynamic[plane, clockwise, [record]] move (int plane, boolean clockwise, record=false) { // any argument without a type is assumed to be the same type as the last element behind it
  34.    super.move(plane, clockwise);
  35.    if (record) {
  36.        moveRecord.add(new Move(plane, clockwise));
  37.    }
  38. }
  39. ```
  40.  
  41. I know the syntax is bad and is even more confusing than overloading for now. I will find a better way, hopefully.
  42.  
  43. Next is the `expose` keyword:
  44. It's simple. Any object that is "exposed" will have its methods accessible directly, like so:
  45. Normal Java code:
  46.  
  47. ```java
  48. private void drawSquare(Vector2 position, Dimension2 size, Color color) {
  49.     int width = size.getWidth();
  50.     int height = size.getHeight();
  51.     BufferedImage square = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
  52.     Graphics2D g = square.createGraphics();
  53.     g.setColor(color);
  54.     g.drawRect(position.getX(), position.getY(), width, height);
  55.     g.dispose();
  56.     canvas.addImage(square);
  57. }
  58. ```
  59.  
  60. ```java
  61. private drawSquare(exposed Vector2 position, exposed Dimension2 size, Color color) { // exposing args objects, their fields as x, y are now accessible directly
  62.     BufferedImage square = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); // direct access to size.getWidth(), etc.
  63.     Graphics2D g = square.createGraphics();
  64.     expose g { // you can also make expose code blocks, now g methods are exposed
  65.         setColor(color);
  66.         drawRect(x, y, width, height);
  67.         dispose();
  68.         canvas.addImage(square);
  69.     }
  70. }
  71. ```
  72.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement