Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How pattern works?

 
AshutoshP Patil
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

hi,
can anybody please help me out in the below mentioned factors

1)how the pattern works ? is it a abstract class or singleton class?

2)the part // 1 " st.mt1.find();" which calls the method find() returns a Boolean value true or false .
but the return of this method is not assigned to any variable ? Then how this works ?

Thanks in Advance


 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
AshutoshP Patil wrote:1)how the pattern works ? is it a abstract class or singleton class?

Not sure what you're asking here. Pattern is a class, it has static methods, it has instance methods, like many other classes.
2)the part // 1 " st.mt1.find();" which calls the method find() returns a Boolean value true or false .
but the return of this method is not assigned to any variable ? Then how this works ?

Just because a method returns a variable doesn't mean it has to be used.
 
AshutoshP Patil
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@david just because the method returns the variable it has to be used


my point is since this function is returning a Boolean value , it must be contained into a variable.(may or may not be used)

 
John de Michele
Rancher
Posts: 600
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
AshutoshP Patil wrote:
my point is since this function is returning a Boolean value , it must be contained into a variable.(may or may not be used)


No, actually it doesn't. The JVM will happily toss out values and references that you don't assign.

John.
 
AshutoshP Patil
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

ok i got. thanks john.
can you please go ahead how this compile method works ?
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why *wouldn't* it work? Have you looked at the Matcher docs?
 
AshutoshP Patil
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
my doubt is how the compile method can take two values
one when it is passed as actual argument
another after passed to method " st.pt1=((Pattern)ob).compile(s[0]);"

will it modify upon the previous pattern instance?

thanks for reply.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm still not sure what you're asking, sorry.
 
Larry Frissell
Ranch Hand
Posts: 82
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
my doubt is how the compile method can take two values
one when it is passed as actual argument
another after passed to method " st.pt1=((Pattern)ob).compile(s[0]);"


compile is not taking two values, in the code ob1 is an instance of Pattern created using the Pattern method "compile(String regex)" then in the method getFormattedObject, the if statement determines that the object is an instance of Pattern. if true, then the Stores object pt1 will equal a Pattern object resulting from the compile(s[0]) or compile("H[a-b][k-m").

Larry
 
AshutoshP Patil
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks i got.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic