• Post Reply Bookmark Topic Watch Topic
  • New Topic

Is there a simple form of do this groups of expressions in one line?  RSS feed

 
Josh Borg
Ranch Hand
Posts: 37
Chrome Eclipse IDE Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I am racking my brains trying to put all this in one line - new DefaultTableModel(0, INT HERE) - there is a way?



Thanks, it's boring I know to answer this kind of stuff.
 
Jacob Draper
Ranch Hand
Posts: 35
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you just want it all on one line or are you saying you want to simplify the code you posted?
Could you provide more detail about what exactly you mean to do?
 
E Armitage
Rancher
Posts: 989
9
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The way to reduce everything to one line is to replace variables with their actual values/expressions. So e.g you would start by replacing primeiroTam on line 5 with ((ArrayList)valorPrimeiro.get(0)).size()+1.
Now you don't need the line anymore. Then you do a similar thing with valorPrimeiro.

The question though is why would you want to do that? you should be striving to make your code as readable as you can. Is the one line version more readable than the many lines versions?

 
sai rama krishna
Ranch Hand
Posts: 536
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I personally feel simplifying too much to too short lines may omplicate things esp to understand and debug later by other people.
 
Paweł Baczyński
Bartender
Posts: 2083
44
Firefox Browser IntelliJ IDE Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Josh Borg wrote:

Are you really sure that you want to declare a List of ArrayLists and assign a raw ArrayList to it?
I don't think it is a good idea.
 
Josh Borg
Ranch Hand
Posts: 37
Chrome Eclipse IDE Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


With this I'm okay, but there is an way do put valorPrimeiro instruction inside new DefaultTableModel constructor's second argument? Like:
valores.get(0).((ArrayList)valorPrimeiro.get(0)).size()+1
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66307
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you feel that would improve the clarity of the code?
 
Josh Borg
Ranch Hand
Posts: 37
Chrome Eclipse IDE Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:Do you feel that would improve the clarity of the code?

I didn't understand what you mean. But I did a mistake. I want it:

How should I cast it correctly?

Pawel Pawlowicz wrote:
Josh Borg wrote:

Are you really sure that you want to declare a List of ArrayLists and assign a raw ArrayList to it?
I don't think it is a good idea.

Why not? What should I do?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66307
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Josh Borg wrote:
Bear Bibeault wrote:Do you feel that would improve the clarity of the code?

I didn't understand what you mean.

Does compacting the code like that make it better? Is it more or less readable?

Imagine you are going to give this line of code to someone else. Will they easily be able to know what it does? Imagine you will walk away from this code for a year. When you look at it after a year, will you know what it does?

Remember, code should never be clever; it should be clear.
 
Josh Borg
Ranch Hand
Posts: 37
Chrome Eclipse IDE Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:
Josh Borg wrote:
Bear Bibeault wrote:Do you feel that would improve the clarity of the code?

I didn't understand what you mean.

Does compacting the code like that make it better? Is it more or less readable?

Imagine you are going to give this line of code to someone else. Will they easily be able to know what it does? Imagine you will walk away from this code for a year. When you look at it after a year, will you know what it does?

Remember, code should never be clever; it should be clear.


It was a personal project and I learn how to do this cast anyway.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!